Skip to content

Commit

Permalink
Marking endpoints and specs thereof
Browse files Browse the repository at this point in the history
  • Loading branch information
nathansobo committed Jan 20, 2008
1 parent 195aa17 commit 9540aad
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/treetop/runtime/interval_skip_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def containing(n)
def insert(range, marker)
first_node = insert_node(range.first)
last_node = insert_node(range.last)
last_node.endpoint_of.push(marker)

cur_node = first_node
cur_level = first_node.height - 1
Expand Down Expand Up @@ -131,12 +132,13 @@ def initialize(height)
end

class Node < HeadNode
attr_reader :key, :markers
attr_reader :key, :markers, :endpoint_of

def initialize(key, height, path)
super(height)
@key = key
@markers = []
@endpoint_of = []

update_forward_pointers(path)
promote_markers(path)
Expand Down
56 changes: 56 additions & 0 deletions spec/runtime/interval_skip_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def confirm_containing_intervals(range, *markers)
it "has no markers" do
node.markers.should be_empty
end

it "is not an endpoint of any interval" do
node.endpoint_of.should be_empty
end
end

describe " #nodes[1]" do
Expand All @@ -110,6 +114,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a as its only marker" do
node.markers.should have_marker(:a)
end

it "is an endpoint of only :a" do
node.endpoint_of.should have_marker(:a)
end
end

describe ", and then :b is inserted on 1..5" do
Expand Down Expand Up @@ -154,6 +162,10 @@ def confirm_containing_intervals(range, *markers)
it "has no markers" do
node.markers.should be_empty
end

it "is not an endpoint of any interval" do
node.endpoint_of.should be_empty
end
end

describe " #nodes[1]" do
Expand All @@ -177,6 +189,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a and :b as its only markers" do
node.markers.should have_markers(:a, :b)
end

it "is an endpoint of only :b" do
node.endpoint_of.should have_marker(:b)
end
end

describe " #nodes[2]" do
Expand All @@ -198,6 +214,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a its only marker" do
node.markers.should have_marker(:a)
end

it "is an endpoint of only :a" do
node.endpoint_of.should have_marker(:a)
end
end

describe ", and then :c is inserted on 1..3" do
Expand Down Expand Up @@ -226,6 +246,10 @@ def confirm_containing_intervals(range, *markers)
it "has no markers" do
node.markers.should be_empty
end

it "is not an endpoint of any interval" do
node.endpoint_of.should be_empty
end
end

describe " #nodes[1]" do
Expand Down Expand Up @@ -253,6 +277,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a, :b, and :c as its only markers" do
node.markers.should have_markers(:a, :b, :c)
end

it "is an endpoint of only :c" do
node.endpoint_of.should have_marker(:c)
end
end

describe " #nodes[2]" do
Expand All @@ -273,6 +301,10 @@ def confirm_containing_intervals(range, *markers)
it "has :b as its only markers" do
node.markers.should have_marker(:b)
end

it "is an endpoint of only :b" do
node.endpoint_of.should have_marker(:b)
end
end

describe " #nodes[3]" do
Expand All @@ -294,6 +326,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a as its only marker" do
node.markers.should have_marker(:a)
end

it "is an endpoint of only :a" do
node.endpoint_of.should have_marker(:a)
end
end

describe ", and then :d is inserted on 1..9" do
Expand Down Expand Up @@ -322,6 +358,10 @@ def confirm_containing_intervals(range, *markers)
it "has no markers" do
node.markers.should be_empty
end

it "is not an endpoint of any interval" do
node.endpoint_of.should be_empty
end
end

describe " #nodes[1]" do
Expand Down Expand Up @@ -349,6 +389,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a, :b, :c, :d as its only markers" do
node.markers.should have_markers(:a, :b, :c, :d)
end

it "is an endpoint of only :c" do
node.endpoint_of.should have_marker(:c)
end
end

describe " #nodes[2]" do
Expand All @@ -369,6 +413,10 @@ def confirm_containing_intervals(range, *markers)
it "has :b as its only marker" do
node.markers.should have_marker(:b)
end

it "is an endpoint of only :b" do
node.endpoint_of.should have_marker(:b)
end
end

describe " #nodes[3]" do
Expand All @@ -393,6 +441,10 @@ def confirm_containing_intervals(range, *markers)
it "has :a, :d as its only markers" do
node.markers.should have_markers(:a, :d)
end

it "is an endpoint of only :a" do
node.endpoint_of.should have_marker(:a)
end
end

describe " #nodes[4]" do
Expand All @@ -412,6 +464,10 @@ def confirm_containing_intervals(range, *markers)
it "has :d as its only marker" do
node.markers.should have_marker(:d)
end

it "is an endpoint of only :d" do
node.endpoint_of.should have_marker(:d)
end
end
end
end
Expand Down

0 comments on commit 9540aad

Please sign in to comment.