Class: Sperm::Groups::GroupsCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/sperm/groups/collection.rb

Overview

Represents collection of known cyclic groups that can be used for generating random permutations.

Constant Summary collapse

DEFAULT_FILE =
File.expand_path('../../../../data/groups.yml', __FILE__)
DEFAULT =
load_file(DEFAULT_FILE)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(isomorphisms) ⇒ GroupsCollection


13
14
15
# File 'lib/sperm/groups/collection.rb', line 13

def initialize(isomorphisms)
  @isomorphisms = isomorphisms.sort_by { |isomorphism| isomorphism.order }
end

Class Method Details

.load_file(path) ⇒ Object


21
22
23
24
25
26
27
28
29
# File 'lib/sperm/groups/collection.rb', line 21

def self.load_file(path)
  array = YAML.load_file(path)
  isomorphisms = array.map { |hash| OpenStruct.new(hash) }.map do |group|
    add_group = ZnAdd.new(group.order_factors)
    mul_group = ZpMul.new(group.prime, group.generator)
    Isomorphism.new(add_group, mul_group)
  end
  new(isomorphisms)
end

Instance Method Details

#find_suitable_isomorphism(order) ⇒ Object


17
18
19
# File 'lib/sperm/groups/collection.rb', line 17

def find_suitable_isomorphism(order)
  @isomorphisms.bsearch { |isomorphism| isomorphism.order >= order }
end