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

Returns a new instance of HMapData.



205
206
207
208
209
210
211
212
# File 'lib/cocoapods-hmap/hmap_struct.rb', line 205

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



225
226
227
228
229
230
231
# File 'lib/cocoapods-hmap/hmap_struct.rb', line 225

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



214
215
216
217
218
219
220
221
222
223
# File 'lib/cocoapods-hmap/hmap_struct.rb', line 214

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

Returns the serialized fields of the mafile.

Returns:

  • (String)

    the serialized fields of the mafile



234
235
236
237
238
239
240
241
242
243
244
# File 'lib/cocoapods-hmap/hmap_struct.rb', line 234

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