dskiplist 0.0.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/dskiplist.gemspec +1 -0
- data/lib/.dskiplist.rb.swo +0 -0
- data/lib/dskiplist/version.rb +1 -1
- data/lib/dskiplist.rb +17 -18
- data/test/skiplist_spec.rb +11 -6
- metadata +16 -4
- data/.dskiplist.gemspec.swo +0 -0
- data/.skiplist-test.rb.swo +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4ae3f9e4947138a5eff42cf7e5ba9d3880efdae
|
4
|
+
data.tar.gz: 11d5d9ef6b19298fa1a65cf89837ecf0d0197f02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28887ea80ed34d66a994d0cc6f055c399d8a14ba87b63be7885432d24d6a166b67bc6732eb5a7df46981b1d1370849dac15db03879314b9b88141681b0fe9519
|
7
|
+
data.tar.gz: 4002864d186702f36c99ab3679ef76d09c29aa425918c1bd5d2e971b0ea97a3686bdfbdad21e9cf383b1e77fc3d19fe8a612b04238f96376674d97c66b068c07
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# DSkipList
|
2
2
|
|
3
|
-
Warning: This software is alpha.
|
3
|
+
Warning: This software is alpha. If you find a bug, please file the issue on github
|
4
4
|
|
5
5
|
This is a ruby skiplist much faster than the ruby skiplist gem here https://github.com/metanest/ruby-skiplist
|
6
6
|
Benchmarks below
|
@@ -27,6 +27,7 @@ require 'dskiplist'
|
|
27
27
|
|
28
28
|
list = DSkipList.new
|
29
29
|
|
30
|
+
#strings and symbols are also valid keys, just keep it consistent
|
30
31
|
list[1] = 'dog'
|
31
32
|
list[2] = 'cat'
|
32
33
|
|
data/dskiplist.gemspec
CHANGED
data/lib/.dskiplist.rb.swo
CHANGED
Binary file
|
data/lib/dskiplist/version.rb
CHANGED
data/lib/dskiplist.rb
CHANGED
@@ -51,25 +51,28 @@ class DSkipList
|
|
51
51
|
initialize(@max_level)
|
52
52
|
return self
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
|
+
#returns previous node if exact key match is not found
|
55
56
|
def find_node(search_key)
|
56
57
|
x = @header
|
57
58
|
@level.downto(0) do |i|
|
59
|
+
#puts "on level #{i}"
|
58
60
|
while x.forward[i] and x.forward[i].key < search_key
|
61
|
+
#puts "walked node #{x.key} on level #{i}"
|
59
62
|
x = x.forward[i]
|
60
63
|
end
|
61
64
|
end
|
62
|
-
x = x.forward[0]
|
63
|
-
|
64
|
-
return x
|
65
|
-
else
|
66
|
-
return nil
|
67
|
-
end
|
65
|
+
x = x.forward[0] if x.forward[0].key == search_key
|
66
|
+
return x
|
68
67
|
end
|
69
68
|
|
70
69
|
def [] key
|
71
70
|
node = self.find_node(key)
|
72
|
-
|
71
|
+
if node and node.key == key
|
72
|
+
return node.value
|
73
|
+
else
|
74
|
+
return nil
|
75
|
+
end
|
73
76
|
end
|
74
77
|
|
75
78
|
def random_level
|
@@ -147,29 +150,25 @@ class DSkipList
|
|
147
150
|
def walk(from, to, limit, level, output)
|
148
151
|
if from
|
149
152
|
x = find_node(from)
|
150
|
-
|
153
|
+
x = x.forward[level] if x.forward[level]
|
151
154
|
else
|
152
155
|
x = @header.forward[level]
|
153
156
|
end
|
154
|
-
if to
|
155
|
-
to_node = find_node(to)
|
156
|
-
raise 'stop node not found' if !to_node
|
157
|
-
end
|
158
|
-
#if no block is given, assume we are trying to count
|
157
|
+
#if no block is given, assume we are trying to count and avoid the expensive yield below
|
159
158
|
if !block_given?
|
160
159
|
count = 0
|
161
160
|
while x
|
161
|
+
break if to && x.key >= to
|
162
162
|
count += 1
|
163
|
-
break if to_node == x
|
164
163
|
x = x.forward[level]
|
165
164
|
end
|
166
165
|
return count
|
167
|
-
elsif
|
166
|
+
elsif to or limit
|
168
167
|
count = 0
|
169
|
-
while x
|
168
|
+
while !x.nil?
|
170
169
|
yield(x, output)
|
171
170
|
count += 1
|
172
|
-
break if
|
171
|
+
break if to and x.key >= to
|
173
172
|
break if limit and count == limit
|
174
173
|
x = x.forward[level]
|
175
174
|
end
|
data/test/skiplist_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rspec'
|
2
|
-
require 'dskiplist'
|
2
|
+
require './lib/dskiplist.rb'
|
3
|
+
require 'pry'
|
3
4
|
#Checks for stray links in the upper levels. There may be a more exhaustive way to check integrity.
|
4
5
|
def check_integrity(list)
|
5
6
|
complete = list.to_a
|
@@ -12,6 +13,7 @@ def check_integrity(list)
|
|
12
13
|
end
|
13
14
|
|
14
15
|
describe "The skiplist" do
|
16
|
+
puts "test suite launching"
|
15
17
|
before :each do
|
16
18
|
@list = DSkipList.new
|
17
19
|
100.times {|n| @list[n] = n}
|
@@ -21,6 +23,7 @@ describe "The skiplist" do
|
|
21
23
|
end
|
22
24
|
|
23
25
|
it "should lookup value correctly" do
|
26
|
+
puts "30 returned #{@list[30]}"
|
24
27
|
expect(@list[30]).to eq(30)
|
25
28
|
end
|
26
29
|
|
@@ -31,14 +34,14 @@ describe "The skiplist" do
|
|
31
34
|
|
32
35
|
it "should count correctly" do
|
33
36
|
expect(@list.count).to eq(100)
|
34
|
-
expect(@list.count(50,99)).to eq(
|
35
|
-
expect(@list.count(1,1)).to eq(
|
37
|
+
expect(@list.count(50,99)).to eq(48)
|
38
|
+
expect(@list.count(1,1)).to eq(0)
|
36
39
|
end
|
37
40
|
|
38
41
|
it "should convert to array" do
|
39
42
|
entire = @list.to_a
|
40
43
|
expect(entire.count).to eq(100)
|
41
|
-
subset = @list.to_a(
|
44
|
+
subset = @list.to_a(25,50)
|
42
45
|
expect(subset.count).to eq(25)
|
43
46
|
26.upto(50) do |n|
|
44
47
|
expect(subset.include? n).to eq(true)
|
@@ -47,9 +50,9 @@ describe "The skiplist" do
|
|
47
50
|
|
48
51
|
it "should convert to hash" do
|
49
52
|
expect(@list.to_h.count).to eq(100)
|
50
|
-
expect(@list.to_h(
|
53
|
+
expect(@list.to_h(50,75).count).to eq(25)
|
51
54
|
subset = @list.to_h(25,50)
|
52
|
-
|
55
|
+
26.upto(50) do |n|
|
53
56
|
expect(subset[n]).to eq(n)
|
54
57
|
end
|
55
58
|
end
|
@@ -62,5 +65,7 @@ describe "The skiplist" do
|
|
62
65
|
it "should delete multiple elements properly" do
|
63
66
|
(25..75).each {|n| @list.delete n}
|
64
67
|
(25..75).each {|n| expect(@list[n]).to eq(nil)}
|
68
|
+
#check sizes of each level to make sure we aren't chopping off the tail when we delete. Seems fine
|
69
|
+
#@list.level.downto(0) {|l| puts "level #{l} contains #{@list.count(nil, nil, l)}"}
|
65
70
|
end
|
66
71
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dskiplist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Forrest Allison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description:
|
56
70
|
email:
|
57
71
|
- light24bulbs@gmail.com
|
@@ -59,7 +73,6 @@ executables: []
|
|
59
73
|
extensions: []
|
60
74
|
extra_rdoc_files: []
|
61
75
|
files:
|
62
|
-
- ".dskiplist.gemspec.swo"
|
63
76
|
- ".git-new/HEAD"
|
64
77
|
- ".git-new/config"
|
65
78
|
- ".git-new/description"
|
@@ -82,7 +95,6 @@ files:
|
|
82
95
|
- ".git-new/objects/ae/ee3428c017916e5cc0e57d387224f33ed0b990"
|
83
96
|
- ".git-new/objects/d8/7d4be66f458acd52878902bbf1391732ad21e1"
|
84
97
|
- ".gitignore"
|
85
|
-
- ".skiplist-test.rb.swo"
|
86
98
|
- Gemfile
|
87
99
|
- LICENSE.txt
|
88
100
|
- README.md
|
data/.dskiplist.gemspec.swo
DELETED
Binary file
|
data/.skiplist-test.rb.swo
DELETED
Binary file
|