Sha256: 06ec46f6117979c4b682245a0ffccee024ba3aa471b6679901964dbc57ce71ad
Contents?: true
Size: 492 Bytes
Versions: 2
Compression:
Stored size: 492 Bytes
Contents
# frozen_string_literal: true class LevelNodes attr_reader :size def initialize(nodes) @hash = Hash.new{|h, k| h[k] = [] } @hash[0] = nodes.sort @size = nodes.size end def pop_min_node level, nodes = @hash.min_by{|_, v| v[0] } node = nodes.shift @hash.delete(level) if nodes.size == 0 @size -= 1 return level, node end def push_node(level, node) @hash[level] << node @hash[level].sort! @size += 1 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
huffman_coding-1.1.0 | lib/huffman_coding/level_nodes.rb |
huffman_coding-1.0.0 | lib/huffman_coding/level_nodes.rb |