Class: Andromeda::Impl::XorId

Inherits:
Object
  • Object
show all
Includes:
To_S
Defined in:
lib/andromeda/impl/id.rb,
lib/andromeda/impl/xor_id.rb

Overview

Generator for random xorable ids (used for markers)

Direct Known Subclasses

Andromeda::Id

Instance Method Summary collapse

Methods included from To_S

short_s, #to_s

Instance Method Details

#==(b) ⇒ Object

Compare self to b

Parameters:



41
42
43
44
45
46
47
48
# File 'lib/andromeda/impl/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/id.rb', line 32

def [](key) ; @data[key] end

#clone_to_copy?Boolean

Returns:

  • (Boolean)


26
# File 'lib/andromeda/impl/id.rb', line 26

def clone_to_copy? ; false end

#eachObject



36
# File 'lib/andromeda/impl/id.rb', line 36

def each ; this = self ; 0.upto(length-1).each { |i| yield this[i] } end

#each_with_indexObject



37
# File 'lib/andromeda/impl/id.rb', line 37

def each_with_index ; this = self ; 0.upto(length-1).each { |i| yield i, this[i] } end

#hashObject



50
# File 'lib/andromeda/impl/id.rb', line 50

def hash ; @data.hash end

#identical_copyObject



27
# File 'lib/andromeda/impl/id.rb', line 27

def identical_copy ; self end

#inspectObject



67
# File 'lib/andromeda/impl/id.rb', line 67

def inspect ; to_s end

#lengthObject



29
# File 'lib/andromeda/impl/id.rb', line 29

def length ; @data.length end

#same_length?(obj) ⇒ Boolean

Returns:

  • (Boolean)


34
# File 'lib/andromeda/impl/id.rb', line 34

def same_length?(obj) ; self.length == obj.length end

#to_short_sObject



61
62
63
64
65
# File 'lib/andromeda/impl/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

Parameters:

Returns:



55
56
57
58
59
# File 'lib/andromeda/impl/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

Returns:

  • (Boolean)


30
# File 'lib/andromeda/impl/id.rb', line 30

def zero? ; each { |b| return false unless b == 0 } ; true end