Created
July 2, 2012 05:13
-
-
Save bnagy/3031219 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def tc_deflate!( set ) | |
# Single thread / core only! | |
[email protected]/2 | |
cached={} | |
set.map! {|elem| | |
unless (idx=@tc[elem]) #already there | |
cur+=1 | |
cached[cur]=elem | |
cached[elem]=cur | |
Integer( cur ) | |
else | |
Integer( idx ) | |
end | |
} | |
@tc.update cached | |
set | |
end | |
def redis_store( word ) | |
# Safe concurrent access to the Redis DB | |
loop do | |
@redis.watch("words") | |
value = @redis.hget("words", word) | |
@redis.unwatch and break(value) if value | |
idx = (@redis.hlen("words")/2).to_s | |
break(idx) if @redis.multi do | |
@redis.hmset("words", word, idx, idx, word) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment