triez 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,116 @@
1
+ require "test/unit"
2
+ require_relative "../lib/triez"
3
+
4
+ GC.stress
5
+
6
+ class TriezTest < Test::Unit::TestCase
7
+ def test_init_options
8
+ t = Triez.new obj_value: true
9
+ assert_equal true, t.obj_value?
10
+ assert_equal false, t.suffix?
11
+ t = Triez.new suffix: true
12
+ assert_equal true, t.suffix?
13
+ assert_equal false, t.obj_value?
14
+ end
15
+
16
+ def test_hat_trie
17
+ t = Triez.new obj_value: true
18
+
19
+ v1 = (1 << 40)
20
+ v2 = (1 << 141)
21
+ t['万塘路一锅鸡'] = v1
22
+ t['万塘路'] = v2
23
+ assert_equal v1, t['万塘路一锅鸡']
24
+ assert_equal v2, t['万塘路']
25
+ assert_equal nil, t['万']
26
+ assert_equal false, t.has_key?('万')
27
+ assert_equal true, t.has_key?('万塘路')
28
+
29
+ assert_equal v1, t.delete('万塘路一锅鸡')
30
+ assert_equal nil, t['万塘路一锅鸡']
31
+ assert_equal v2, t['万塘路']
32
+
33
+ a = t.search_with_prefix ''
34
+ assert_equal [['万塘路', v2]], a
35
+
36
+ t['马当路'] = 3
37
+ a = t.search_with_prefix '万塘'
38
+ assert_equal [['路', v2]], a
39
+ end
40
+
41
+ def test_insertion_and_search_on_many_keys
42
+ t = Triez.new
43
+ as = ('A'..'z').to_a
44
+ bs = ('一'..'百').to_a
45
+ as.each do |a|
46
+ # 10k chars to ensure burst
47
+ bs.each do |b|
48
+ t[a + b] = 0
49
+ end
50
+ end
51
+ assert_equal as.size * bs.size, t.size
52
+
53
+ a = t.search_with_prefix 'a'
54
+ assert_equal bs.to_a, a.map(&:first).sort
55
+
56
+ a = []
57
+ t.search_with_prefix 'b', sort: true, limit: 3 do |k, v|
58
+ a << k
59
+ end
60
+ assert_equal 3, a.size
61
+ assert_equal a, a.sort
62
+ end
63
+
64
+ def test_each_and_raise
65
+ t = Triez.new
66
+ t['abcd'] = 0
67
+ t['abc'] = 1
68
+
69
+ assert_raise NameError do
70
+ t.each do |k, v|
71
+ raise NameError, k
72
+ end
73
+ end
74
+
75
+ assert_raise ArgumentError do
76
+ t.each
77
+ end
78
+ end
79
+
80
+ def test_append
81
+ t = Triez.new
82
+ ('a'..'z').each do |c|
83
+ t << c
84
+ end
85
+ assert_equal 26, t.size
86
+ assert_equal 0, t['c']
87
+ assert_equal true, t.has_key?('c')
88
+ end
89
+
90
+ def test_suffix_insert
91
+ t = Triez.new suffix: true
92
+ t << '12345'
93
+ assert_equal 5, t.size
94
+ end
95
+
96
+ def test_full_text_search
97
+ sequences = {
98
+ 'ACTGAAAAAAACTG' => 1,
99
+ 'ATACGGTCCA' => 2,
100
+ 'GCTTGTACGT' => 3
101
+ }
102
+ t = Triez.new suffix: true
103
+ sequences.each do |seq, id|
104
+ t[seq] = id
105
+ end
106
+ assert_equal 2, t.search_with_prefix('CGGT').map(&:last).flatten.first
107
+ end
108
+
109
+ def test_nul_char_in_keys
110
+ t = Triez.new
111
+ t["a\0b"] = 1
112
+ assert_equal 1, t["a\0b"]
113
+ assert_equal 1, t.size
114
+ assert_equal nil, t["a"]
115
+ end
116
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: triez
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zete Lui
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-04 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: fast, efficient, unicode aware HAT trie with prefix / suffix support.
15
+ email:
16
+ executables: []
17
+ extensions:
18
+ - ext/extconf.rb
19
+ extra_rdoc_files: []
20
+ files:
21
+ - copying
22
+ - readme.md
23
+ - lib/triez.rb
24
+ - test/triez_test.rb
25
+ - ext/hat-stub.c
26
+ - ext/triez.cc
27
+ - ext/common.h
28
+ - ext/extconf.rb
29
+ - ext/hat-trie/ahtable.c
30
+ - ext/hat-trie/ahtable.h
31
+ - ext/hat-trie/COPYING
32
+ - ext/hat-trie/hat-trie.c
33
+ - ext/hat-trie/hat-trie.h
34
+ - ext/hat-trie/misc.h
35
+ - ext/hat-trie/murmurhash3.c
36
+ - ext/hat-trie/murmurhash3.h
37
+ - ext/hat-trie/pstdint.h
38
+ homepage: https://github.com/luikore/triez
39
+ licenses: []
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: 1.9.2
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 1.8.24
59
+ signing_key:
60
+ specification_version: 3
61
+ summary: fast, efficient, unicode aware HAT trie with prefix / suffix support
62
+ test_files: []
63
+ has_rdoc: false