Class: Andromeda::Impl::XorId
- Includes:
- To_S
- Defined in:
- lib/andromeda/impl/xor_id.rb
Overview
Generator for random xorable ids (used for markers)
Direct Known Subclasses
Instance Method Summary collapse
-
#==(b) ⇒ Object
Compare self to b.
- #[](key) ⇒ Object
- #clone_to_copy? ⇒ Boolean
- #each ⇒ Object
- #each_with_index ⇒ Object
- #hash ⇒ Object
- #identical_copy ⇒ Object
- #inspect ⇒ Object
- #length ⇒ Object
- #same_length?(obj) ⇒ Boolean
- #to_short_s ⇒ Object
-
#xor(b) ⇒ Id
xor self and b’s ids component-wise.
- #zero? ⇒ Boolean
Methods included from To_S
Instance Method Details
#==(b) ⇒ Object
Compare self to b
41 42 43 44 45 46 47 48 |
# File 'lib/andromeda/impl/xor_id.rb', line 41 def ==(b) return true if self.equal? b return false if b.nil? return false unless b.class.equal? self.class return false unless same_length? b zip_bytes(b) { |i, j| return false if i != j } true end |
#[](key) ⇒ Object
32 |
# File 'lib/andromeda/impl/xor_id.rb', line 32 def [](key) ; @data[key] end |
#clone_to_copy? ⇒ Boolean
26 |
# File 'lib/andromeda/impl/xor_id.rb', line 26 def clone_to_copy? ; false end |
#each ⇒ Object
36 |
# File 'lib/andromeda/impl/xor_id.rb', line 36 def each ; this = self ; 0.upto(length-1).each { |i| yield this[i] } end |
#each_with_index ⇒ Object
37 |
# File 'lib/andromeda/impl/xor_id.rb', line 37 def each_with_index ; this = self ; 0.upto(length-1).each { |i| yield i, this[i] } end |
#hash ⇒ Object
50 |
# File 'lib/andromeda/impl/xor_id.rb', line 50 def hash ; @data.hash end |
#identical_copy ⇒ Object
27 |
# File 'lib/andromeda/impl/xor_id.rb', line 27 def identical_copy ; self end |
#inspect ⇒ Object
67 |
# File 'lib/andromeda/impl/xor_id.rb', line 67 def inspect ; to_s end |
#length ⇒ Object
29 |
# File 'lib/andromeda/impl/xor_id.rb', line 29 def length ; @data.length end |
#same_length?(obj) ⇒ Boolean
34 |
# File 'lib/andromeda/impl/xor_id.rb', line 34 def same_length?(obj) ; self.length == obj.length end |
#to_short_s ⇒ Object
61 62 63 64 65 |
# File 'lib/andromeda/impl/xor_id.rb', line 61 def to_short_s r = '' each { |b| r << Id.two_char_hex_str(b.to_s(16)) } r end |
#xor(b) ⇒ Id
xor self and b’s ids component-wise
55 56 57 58 59 |
# File 'lib/andromeda/impl/xor_id.rb', line 55 def xor(b) r = [] zip_bytes(b) { |i,j| r << (i ^ j) } Id.new r.length, false, r end |
#zero? ⇒ Boolean
30 |
# File 'lib/andromeda/impl/xor_id.rb', line 30 def zero? ; each { |b| return false unless b == 0 } ; true end |