class HMap::HMapData
HMap
blobs.
Public Class Methods
new(buckets)
click to toggle source
Calls superclass method
# File lib/cocoapods-hmap/hmap_struct.rb, line 152 def initialize(buckets) super() count = buckets.count nums = num_buckets(count, Utils.next_power_of_two(count)) entries = entries(count, nums) @header = populate_hmap_header(nums, entries) @buckets = add_bucket(buckets, nums) end
Public Instance Methods
entries(count, nums)
click to toggle source
# File lib/cocoapods-hmap/hmap_struct.rb, line 172 def entries(count, nums) return count if nums == 8 last_pow = nums >> 1 index = last_pow < 1024 ? 3 : -2 count - (last_pow + 1 + index) / 3 + 1 + last_pow end
num_buckets(count, pow2)
click to toggle source
# File lib/cocoapods-hmap/hmap_struct.rb, line 161 def num_buckets(count, pow2) if count < 8 pow2 <<= 1 if count * 4 >= pow2 * 3 pow2 < 8 ? 8 : pow2 else index = count > 341 ? 2 : -3 padding = count / 85 % 7 + index Utils.next_power_of_two(count * 3 + padding) end end
serialize()
click to toggle source
@return [String] the serialized fields of the mafile
# File lib/cocoapods-hmap/hmap_struct.rb, line 181 def serialize @header.serialize + @buckets.inject('') do |sum, bucket| sum += if bucket.nil? empty_b = [HEADER_CONST[:HMAP_EMPTY_BUCKT_KEY]]*3 empty_b.pack('L<3') else bucket end sum end end
Private Instance Methods
add_bucket(buckets, num)
click to toggle source
# File lib/cocoapods-hmap/hmap_struct.rb, line 195 def add_bucket(buckets, num) buckets.each_with_object(Array.new(num)) do |bucket, sum| serialize = bucket.serialize i = Utils.index_of_range(bucket.uuid, num) loop do sum[i] = serialize if sum[i].nil? break if serialize == sum[i] i = Utils.index_of_range(i += 1, num) end end end
populate_hmap_header(num_buckets, entries)
click to toggle source
# File lib/cocoapods-hmap/hmap_struct.rb, line 208 def populate_hmap_header(num_buckets, entries) strings_offset = HMapHeader.bytesize + HMapBucket.bytesize * num_buckets HMapHeader.new(HEADER_CONST[:HMAP_HEADER_MAGIC_NUMBER], HEADER_CONST[:HMAP_HEADER_VERSION], 0, strings_offset, entries, num_buckets, 0) end