Skip to content

Commit 189c34f

Browse files
committed
Merge pull request kanwei#10 from loganb/master
Fix 1.9 compile error and add Heap#next_key method
2 parents fb40819 + 2284ba9 commit 189c34f

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

ext/algorithms/string/string.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ int min(int a, int b, int c) {
1111

1212
int levenshtein_distance(VALUE str1, VALUE str2) {
1313
int i, j, s1_len, s2_len, *d;
14-
char * s = RSTRING(str1)->ptr;
15-
char * t = RSTRING(str2)->ptr;
16-
s1_len = RSTRING(str1)->len;
17-
s2_len = RSTRING(str2)->len;
14+
char * s = RSTRING_PTR(str1);
15+
char * t = RSTRING_PTR(str2);
16+
s1_len = RSTRING_LEN(str1);
17+
s2_len = RSTRING_LEN(str2);
1818

1919
if (s1_len == 0) {
2020
return s2_len;

lib/containers/heap.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,22 @@ def next
117117
@next && @next.value
118118
end
119119

120+
# call-seq:
121+
# next_key -> key
122+
# next_key -> nil
123+
#
124+
# Returns the key associated with the next item in heap order, but does not remove the value.
125+
#
126+
# Complexity: O(1)
127+
#
128+
# minheap = MinHeap.new
129+
# minheap.push(1, :a)
130+
# minheap.next_key #=> 1
131+
#
132+
def next_key
133+
@next && @next.key
134+
end
135+
120136
# call-seq:
121137
# clear -> nil
122138
#

spec/heap_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@
4646
@heap.size.should eql(@num_items)
4747
end
4848

49+
it "should have a next value" do
50+
@heap.next.should be_true
51+
@heap.next_key.should be_true
52+
end
53+
4954
it "should delete random keys" do
5055
@heap.delete(@random_array[0]).should eql(@random_array[0])
5156
@heap.delete(@random_array[1]).should eql(@random_array[1])

0 commit comments

Comments
 (0)