Skip to content

Commit

Permalink
changed ViewStorage#find to work with SimpleSkiplist#search
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Andreev committed Apr 27, 2008
1 parent 7d7c66e commit 84ec29b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 34 deletions.
6 changes: 1 addition & 5 deletions lib/strokedb/views/view.rb
Expand Up @@ -114,13 +114,9 @@ def ugly_find(start_key, end_key, key, limit, offset, reverse, with_keys)
# Mode 2. startkey..endkey
# Mode 3. key, count (skip) - prefix search

if key
end_key = start_key = key
end

array = storage.find(start_key && encode_key(start_key),
end_key && encode_key(end_key),
encode_key(key),
key && encode_key(key),
limit,
offset,
reverse,
Expand Down
31 changes: 3 additions & 28 deletions lib/strokedb/views/view_storage.rb
Expand Up @@ -19,36 +19,11 @@ def set_options(options)

#
#
def find(start_key, end_key, limit, offset, reverse, with_keys)
def find(start_key, end_key, key, limit, offset, reverse, with_keys)
start_key = end_key = key if key
@list.search(start_key, end_key, limit, offset, reverse, with_keys)
end

#
#
def find_(start_key, end_key, key, limit, offset, reverse, with_keys)
start_key = end_key = key if start_key.nil? && end_key.nil?
# Please note that below algorithm will most probably be eventually replaced by a new skiplist Oleg Andreev works on currently
start_key = @list.first_key unless start_key
current_key = start_key
offset ||= 0

items = []
item = @list.find_nearest_node(current_key)

offset.times do
item = item[0][0] # next node
end

until item.nil?
items << (with_keys ? [item[1],item[2]] : item[2]) # [1] is a node_key [2] is a node_value
break if (current_key = item[1]) == end_key
break if items.size == limit
item = item[0][0] # next node
end

items
end


#
#
def replace(old_pairs, new_pairs)
Expand Down
6 changes: 5 additions & 1 deletion spec/lib/strokedb/views/view_storage_spec.rb
Expand Up @@ -19,7 +19,8 @@
@insertion = lambda {|key, val| @view_storage.insert([[key, val]]) }
end

it "should store reference to Document" do
it "should store reference to a Document" do
pending "move this spec to view_spec"
@value = Document.new
@insertion.call('key',@value)
@view_storage.find(nil, nil, 'key', nil, nil, false, false).to_set.should == [@value].to_set
Expand All @@ -46,6 +47,7 @@
end

it "should store references to Documents" do
pending "move this spec to view_spec"
@value_1 = Document.new
@value_2 = Document.new
@insertion.call(['key','another_key'],[@value_1, @value_2])
Expand All @@ -72,6 +74,7 @@
end

it "should replace existing reference to Document if such pair exists already" do
pending "move this spec to view_spec"
@value_1 = Document.new
@value_2 = Document.new

Expand Down Expand Up @@ -114,6 +117,7 @@
end

it "should replace existing references to Document if such pairs exist already" do
pending "move this spec to view_spec"
@value_1 = Document.new
@value_2 = Document.new

Expand Down

0 comments on commit 84ec29b

Please sign in to comment.