Sha256: acd4ca2272466503c8bd1fe7a16c65d26d5282eaf169821e3d3cc8757b8e83d7

Contents?: true

Size: 1007 Bytes

Versions: 1

Compression:

Stored size: 1007 Bytes

Contents

require 'sperm/groups/additive'
require 'sperm/groups/multiplicative'
require 'sperm/groups/isomorphism'

require 'ostruct'
require 'yaml'

module Sperm::Groups
  # Represents collection of known cyclic groups that can be used
  # for generating random permutations.
  #
  class GroupsCollection
    def initialize(isomorphisms)
      @isomorphisms = isomorphisms.sort_by { |isomorphism| isomorphism.order }
    end

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

    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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sperm-0.1.1 lib/sperm/groups/collection.rb