Class: HMap::HMapSaver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHMapSaver



7
8
9
10
11
# File 'lib/cocoapods-hmap/hmap_save.rb', line 7

def initialize
  @string_table = "\0"
  @buckets = []
  @headers = {}
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets.



5
6
7
# File 'lib/cocoapods-hmap/hmap_save.rb', line 5

def buckets
  @buckets
end

#headersObject (readonly)

Returns the value of attribute headers.



5
6
7
# File 'lib/cocoapods-hmap/hmap_save.rb', line 5

def headers
  @headers
end

#string_tableObject (readonly)

Returns the value of attribute string_table.



5
6
7
# File 'lib/cocoapods-hmap/hmap_save.rb', line 5

def string_table
  @string_table
end

Instance Method Details

#add_to_buckets(*buckets) ⇒ Object



35
36
37
38
39
40
# File 'lib/cocoapods-hmap/hmap_save.rb', line 35

def add_to_buckets(*buckets)
  values = buckets.map { |key| add_to_headers(key) }
  bucket = HMapBucket.new(*values)
  bucket.uuid = Utils.string_downcase_hash(buckets.first)
  @buckets << bucket
end

#add_to_headers(key) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/cocoapods-hmap/hmap_save.rb', line 27

def add_to_headers(key)
  if headers[key].nil?
    headers[key] = string_table.length
    add_to_string_table(key)
  end
  headers[key]
end

#add_to_string_table(str) ⇒ Object



23
24
25
# File 'lib/cocoapods-hmap/hmap_save.rb', line 23

def add_to_string_table(str)
  @string_table += "#{Utils.safe_encode(str, 'ASCII-8BIT')}\0"
end

#header_to_hash(keys, headers, index, buckets) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cocoapods-hmap/hmap_save.rb', line 13

def header_to_hash(keys, headers, index, buckets)
  index = index.length
  keys.inject('') do |sum, bucket|
    buckte = HMapBucketStr.new(*bucket)
    string_t = buckte.bucket_to_string(headers, index + sum.length)
    buckets.push(buckte)
    sum + string_t
  end
end

#write_to(path) ⇒ Object



42
43
44
# File 'lib/cocoapods-hmap/hmap_save.rb', line 42

def write_to(path)
  MapFile.new(@string_table, @buckets).write(path)
end