Sha256: 00ab0089c49540a6b42e7114712d5b1e1e5baa9da4d0fb4ed6dc959e415fb6cf
Contents?: true
Size: 1.44 KB
Versions: 19
Compression:
Stored size: 1.44 KB
Contents
# frozen_string_literal: true require 'eac_ruby_utils/core_ext' require 'ehbrs_ruby_utils/circular_list_spreader/base_level' require 'ehbrs_ruby_utils/circular_list_spreader/item_level' module EhbrsRubyUtils class CircularListSpreader class GroupLevel include ::EhbrsRubyUtils::CircularListSpreader::BaseLevel enable_simple_cache common_constructor :label def push(path, item) child_path = path.dup current = child_path.shift if child_path.any? push_group_level(current, child_path, item) else push_item_level(current, item) end end def pop children.values.max.pop end def pop_all r = [] while remaining?; r << pop; end r end def remaining_i children.values.inject(0) { |a, e| a + e.remaining_i } end def total_i children.values.inject(0) { |a, e| a + e.total_i } end private attr_accessor :item def push_group_level(current, child_path, item) children[current] ||= self.class.new(current) children[current].push(child_path, item) end def children @children ||= {} end def push_item_level(current, item) raise "Key \"#{current}\" already used" if children[current].present? children[current] = ::EhbrsRubyUtils::CircularListSpreader::ItemLevel.new(item) end end end end
Version data entries
19 entries across 19 versions & 1 rubygems