lsh 0.1.4-java → 0.1.6-java

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.
Files changed (2) hide show
  1. data/lib/lsh/storage/redis_backend.rb +18 -7
  2. metadata +2 -2
@@ -35,8 +35,18 @@ module LSH
35
35
  end
36
36
 
37
37
  def reset!
38
- @redis.flushall
38
+ clear_data!
39
+ clear_projections!
40
+ end
41
+
42
+ def clear_data!
43
+ @redis.del(@redis.keys("lsh:bucket:*"))
39
44
  delete_dat_files_in_dir(@data_dir)
45
+ end
46
+
47
+ def clear_projections!
48
+ @redis.del("lsh:parameters")
49
+ @redis.del("lsh:buckets")
40
50
  delete_dat_files_in_dir(File.join(@data_dir, 'projections'))
41
51
  end
42
52
 
@@ -49,7 +59,7 @@ module LSH
49
59
  end
50
60
 
51
61
  def number_of_buckets
52
- @redis.get("buckets") || 0
62
+ @redis.get("lsh:buckets").to_i || 0
53
63
  end
54
64
 
55
65
  def projections=(projections)
@@ -82,13 +92,13 @@ module LSH
82
92
 
83
93
  def parameters=(parms)
84
94
  parms[:window] = 'Infinity' if parms[:window] == Float::INFINITY
85
- @redis.set "parameters", parms.to_json
95
+ @redis.set "lsh:parameters", parms.to_json
86
96
  end
87
97
 
88
98
  def parameters
89
99
  begin
90
100
  @parms ||= (
91
- parms = JSON.parse(@redis.get "parameters")
101
+ parms = JSON.parse(@redis.get "lsh:parameters")
92
102
  parms.keys.each { |k| parms[k.to_sym] = parms[k]; parms.delete(k) }
93
103
  parms[:window] = Float::INFINITY if parms[:window] == 'Infinity'
94
104
  parms
@@ -99,7 +109,7 @@ module LSH
99
109
  end
100
110
 
101
111
  def create_new_bucket
102
- @redis.incr "buckets"
112
+ @redis.incr "lsh:buckets"
103
113
  end
104
114
 
105
115
  def add_vector_to_bucket(bucket, hash, vector)
@@ -108,14 +118,15 @@ module LSH
108
118
  end
109
119
 
110
120
  def find_bucket(i)
111
- "bucket:#{i}" if @redis.get("buckets").to_i > i
121
+ "lsh:bucket:#{i}"
112
122
  end
113
123
 
114
124
  def query_buckets(hashes)
115
125
  vector_hashes = []
116
126
  hashes.each_with_index do |hash, i|
117
127
  bucket = find_bucket(i)
118
- vector_hashes += @redis.smembers("#{bucket}:#{hash}")
128
+ results = @redis.smembers("#{bucket}:#{hash}")
129
+ vector_hashes += results if results
119
130
  end
120
131
  # Making sure we don't load the same vectors twice if they match
121
132
  # in different random projections
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: lsh
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.6
6
6
  platform: java
7
7
  authors:
8
8
  - Yves Raimond
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-31 00:00:00.000000000 Z
12
+ date: 2013-01-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jblas-ruby