Skip to content

Commit

Permalink
Changed height of first node to 1 and fixed error that was flushed ou…
Browse files Browse the repository at this point in the history
…t by this change where we weren't properly deleting from the former path when promoting markers multiple levels
  • Loading branch information
nathansobo committed Jan 21, 2008
1 parent 4ff8b09 commit 32b424d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 52 deletions.
3 changes: 2 additions & 1 deletion lib/treetop/runtime/interval_skip_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def promote_markers(path)
incoming_markers.each do |marker|
if can_be_promoted_higher?(marker, i)
new_promoted.push(marker)
forward[i].delete_marker_from_path(marker, i, forward[i+i])
forward[i].delete_marker_from_path(marker, i, forward[i+1])
else
forward_markers[i].push(marker)
end
Expand All @@ -225,6 +225,7 @@ def promote_markers(path)
promoted.each do |marker|
if can_be_promoted_higher?(marker, i)
new_promoted.push(marker)
forward[i].delete_marker_from_path(marker, i, forward[i+1])
else
forward_markers[i].push(marker)
end
Expand Down
78 changes: 27 additions & 51 deletions spec/runtime/interval_skip_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class IntervalSkipList
end
end

describe IntervalSkipList, " when #next_node_height returns 2, 3, 2, 3, 1 in order" do
describe IntervalSkipList, " when #next_node_height returns 1, 3, 2, 3, 1 in order" do
attr_reader :list, :node
include IntervalSkipListSpecHelper

Expand All @@ -43,7 +43,7 @@ class IntervalSkipList
it_should_behave_like "#next_node_height is deterministic"

def expected_node_heights
[2, 3, 2, 3, 1]
[1, 3, 2, 3, 1]
end

def confirm_containing_intervals(range, *markers)
Expand Down Expand Up @@ -73,24 +73,20 @@ def confirm_containing_intervals(range, *markers)
@node = list.nodes[0]
end

it "has a key of 1 and height of 2" do
it "has a key of 1 and height of 1" do
node.key.should == 1
node.height.should == 2
node.height.should == 1
end

it "has :a as its only marker at level 1" do
node.forward_markers[1].should have_marker(:a)
end

it "has no forward_markers at level 0" do
node.forward_markers[0].should be_empty
it "has :a as its only marker at level 0" do
node.forward_markers[0].should have_marker(:a)
end

it "has no markers" do
node.markers.should be_empty
end

it "is not an endpoint of only :a" do
it "is an endpoint of only :a" do
node.endpoint_of.should have_marker(:a)
end
end
Expand Down Expand Up @@ -145,17 +141,13 @@ def confirm_containing_intervals(range, *markers)
@node = list.nodes[0]
end

it "has a key of 1 and height of 2" do
it "has a key of 1 and height of 1" do
node.key.should == 1
node.height.should == 2
node.height.should == 1
end

it "has :a and :b as its only forward markers at level 1" do
node.forward_markers[1].should have_markers(:a, :b)
end

it "has no forward markers at level 0" do
node.forward_markers[0].should be_empty
it "has :a and :b as its only forward markers at level 0" do
node.forward_markers[0].should have_markers(:a, :b)
end

it "has no markers" do
Expand Down Expand Up @@ -248,17 +240,13 @@ def confirm_containing_intervals(range, *markers)
@node = list.nodes[0]
end

it "has a key of 1 and height of 2" do
it "has a key of 1 and height of 1" do
node.key.should == 1
node.height.should == 2
node.height.should == 1
end

it "has :a, :b, :c as its only forward markers at level 1" do
node.forward_markers[1].should have_markers(:a, :b, :c)
end

it "has no forward markers at level 0" do
node.forward_markers[0].should be_empty
it "has :a, :b, :c as its only forward markers at level 0" do
node.forward_markers[0].should have_markers(:a, :b, :c)
end

it "has no markers" do
Expand Down Expand Up @@ -389,17 +377,13 @@ def confirm_containing_intervals(range, *markers)
@node = list.nodes[0]
end

it "has a key of 1 and height of 2" do
it "has a key of 1 and height of 1" do
node.key.should == 1
node.height.should == 2
end

it "has :a, :b, :c, :d as its only forward markers at level 1" do
node.forward_markers[1].should have_markers(:a, :b, :c, :d)
node.height.should == 1
end

it "has no forward markers at level 0" do
node.forward_markers[0].should be_empty
it "has :a, :b, :c, :d as its only forward markers at level 0" do
node.forward_markers[0].should have_markers(:a, :b, :c, :d)
end

it "has no markers" do
Expand Down Expand Up @@ -531,17 +515,13 @@ def confirm_containing_intervals(range, *markers)
@node = list.nodes[0]
end

it "has a key of 1 and height of 2" do
it "has a key of 1 and height of 1" do
node.key.should == 1
node.height.should == 2
node.height.should == 1
end

it "has :a, :b, and :c as its only forward markers at level 1" do
node.forward_markers[1].should have_markers(:a, :b, :c)
end

it "has no forward markers at level 0" do
node.forward_markers[0].should be_empty
it "has :a, :b, and :c as its only forward markers at level 0" do
node.forward_markers[0].should have_markers(:a, :b, :c)
end
end

Expand Down Expand Up @@ -639,17 +619,13 @@ def confirm_containing_intervals(range, *markers)
@node = list.nodes[0]
end

it "has a key of 1 and height of 2" do
it "has a key of 1 and height of 1" do
node.key.should == 1
node.height.should == 2
node.height.should == 1
end

it "has :a and :b as its only forward markers at level 1" do
node.forward_markers[1].should have_markers(:a, :b)
end

it "has no forward markers at level 0" do
node.forward_markers[0].should be_empty
it "has :a and :b as its only forward markers at level 0" do
node.forward_markers[0].should have_markers(:a, :b)
end

it "has no markers" do
Expand Down

0 comments on commit 32b424d

Please sign in to comment.