Class: HMap::HMapData

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-hmap/hmap_struct.rb

Overview

HMap blobs.

Instance Method Summary collapse

Constructor Details

#initialize(buckets) ⇒ HMapData



152
153
154
155
156
157
158
159
# 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

Instance Method Details

#entries(count, nums) ⇒ Object



172
173
174
175
176
177
178
# 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) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# 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

#serializeString



181
182
183
184
185
186
187
188
189
190
191
# 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