Skip to content

Commit

Permalink
remove tags, next_tag
Browse files Browse the repository at this point in the history
  • Loading branch information
seki committed Jul 1, 2011
1 parent eed8f48 commit 98174fc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 49 deletions.
30 changes: 0 additions & 30 deletions lib/drip.rb
Expand Up @@ -121,29 +121,6 @@ def key_to_time(key)
Time.at(*key.divmod(1000000))
end

def next_tag(cur=nil, n=1)
return _next_tag(cur) if n == 1
ary = []
while cur = _next_tag(cur)
ary << cur
n -= 1
break if n <= 0
end
ary
end

def tags(prefix='')
ary = []
cur = next_tag(prefix)
while cur && cur.index(prefix) == 0
str = cur.dup
str[prefix] = ''
ary << str
cur = next_tag(cur + "\0")
end
ary
end

private
class SimpleStore
Attic = Struct.new(:fname, :fpos, :value)
Expand Down Expand Up @@ -300,13 +277,6 @@ def wait_tag(key, tag, renewer)
end while key = wait(key, renewer)
end

def _next_tag(cur)
fwd = cur ? cur + "\0" : ''
it ,= @tag.lower_bound([fwd, 0])
return nil unless it
it[0]
end

class Renewer
def initialize(timeout)
@at = Time.now + timeout
Expand Down
22 changes: 3 additions & 19 deletions test/basic.rb
Expand Up @@ -54,33 +54,17 @@ def test_read
assert_equal(tags, ['tag1', 'tag2'])
end

def test_next_tag
11.times do |n|
value = {"n=#{n}" => 'x' * n, n => n, "n" => n, :symbol => n}
@drip.write(value, *value.keys)
end
assert_equal(@drip.next_tag(), 'n')
assert_equal(@drip.next_tag(nil), 'n')
assert_equal(@drip.next_tag('n='), 'n=0')
assert_equal(@drip.next_tag('n=0'), 'n=1')
assert_equal(@drip.next_tag('n=0', 3), ['n=1', 'n=10', 'n=2'])
assert_equal(@drip.tags, ["n",
"n=0", "n=1", "n=10", "n=2", "n=3",
"n=4", "n=5", "n=6", "n=7", "n=8", "n=9"])
# tags with prefix
assert_equal(@drip.tags("n="), %w(0 1 10 2 3 4 5 6 7 8 9))
end

def test_symbol_is_not_tag
@drip.write({:symbol => :symbol, 'string' => :string}, :symbol, 'string')
assert_equal(@drip.tags, ['string'])
assert_raise(ArgumentError) {@drip.read_tag(0, :symbol, 1, 0)}
oid, value = @drip.older(@drip.time_to_key(Time.now))
assert_equal(value, {:symbol => :symbol, 'string' => :string})
end

def test_number_is_not_tag
@drip.write({5 => :five, 'string' => :string}, 5, 'string')
assert_equal(@drip.tags, ['string'])
assert_equal(@drip.read_tag(0, 'string', 1, 0).size, 1)
assert_raise(ArgumentError) {@drip.read_tag(0, 5, 1, 0)}
end

def test_older_now_is_newest
Expand Down

0 comments on commit 98174fc

Please sign in to comment.