Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/algorithms/string/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ int min(int a, int b, int c) {

int levenshtein_distance(VALUE str1, VALUE str2) {
int i, j, s1_len, s2_len, *d;
char * s = RSTRING(str1)->ptr;
char * t = RSTRING(str2)->ptr;
s1_len = RSTRING(str1)->len;
s2_len = RSTRING(str2)->len;
char * s = RSTRING_PTR(str1);
char * t = RSTRING_PTR(str2);
s1_len = RSTRING_LEN(str1);
s2_len = RSTRING_LEN(str2);

if (s1_len == 0) {
return s2_len;
Expand Down
16 changes: 16 additions & 0 deletions lib/containers/heap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def next
@next && @next.value
end

# call-seq:
# next_key -> key
# next_key -> nil
#
# Returns the key associated with the next item in heap order, but does not remove the value.
#
# Complexity: O(1)
#
# minheap = MinHeap.new
# minheap.push(1, :a)
# minheap.next_key #=> 1
#
def next_key
@next && @next.key
end

# call-seq:
# clear -> nil
#
Expand Down
5 changes: 5 additions & 0 deletions spec/heap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
@heap.size.should eql(@num_items)
end

it "should have a next value" do
@heap.next.should be_true
@heap.next_key.should be_true
end

it "should delete random keys" do
@heap.delete(@random_array[0]).should eql(@random_array[0])
@heap.delete(@random_array[1]).should eql(@random_array[1])
Expand Down