Class: HMap::HMapData
- Inherits:
-
Object
- Object
- HMap::HMapData
- Defined in:
- lib/cocoapods-hmap-prebuilt/hmap_struct.rb
Overview
HMap blobs.
Instance Method Summary collapse
- #add_bucket(buckets, num) ⇒ Object
- #entries(count, nums) ⇒ Object
-
#initialize(buckets) ⇒ HMapData
constructor
A new instance of HMapData.
- #num_buckets(count, pow2) ⇒ Object
- #populate_hmap_header(num_buckets, entries) ⇒ Object
-
#serialize ⇒ String
The serialized fields of the mafile.
Constructor Details
#initialize(buckets) ⇒ HMapData
Returns a new instance of HMapData.
203 204 205 206 207 208 209 210 |
# File 'lib/cocoapods-hmap-prebuilt/hmap_struct.rb', line 203 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
#add_bucket(buckets, num) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/cocoapods-hmap-prebuilt/hmap_struct.rb', line 244 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 |
#entries(count, nums) ⇒ Object
223 224 225 226 227 228 229 |
# File 'lib/cocoapods-hmap-prebuilt/hmap_struct.rb', line 223 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
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/cocoapods-hmap-prebuilt/hmap_struct.rb', line 212 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 |
#populate_hmap_header(num_buckets, entries) ⇒ Object
257 258 259 260 261 |
# File 'lib/cocoapods-hmap-prebuilt/hmap_struct.rb', line 257 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 |
#serialize ⇒ String
Returns the serialized fields of the mafile.
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/cocoapods-hmap-prebuilt/hmap_struct.rb', line 232 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 |