Class: HMap::HMapHeader Abstract

Inherits:
HMapStructure show all
Defined in:
lib/hmap/hmap/hmap_struct.rb

Overview

This class is abstract.

HMapHeader structure.

Constant Summary collapse

FORMAT =
'L=1S=2L=4'
SIZEOF =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

24

Constants inherited from HMapStructure

HMap::HMapStructure::SWAPPED

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from HMapStructure

bytesize, format, new_from_bin, swapped?

Constructor Details

#initialize(magic, version, reserved, strings_offset, num_entries, num_buckets, max_value_length) ⇒ HMapHeader

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HMapHeader.



81
82
83
84
85
86
87
88
89
90
# File 'lib/hmap/hmap/hmap_struct.rb', line 81

def initialize(magic, version, reserved, strings_offset, num_entries, num_buckets, max_value_length)
  @magic = magic
  @version = version
  @reserved = reserved
  @strings_offset = strings_offset
  @num_entries = num_entries
  @num_buckets = num_buckets
  @max_value_length = max_value_length
  super()
end

Instance Attribute Details

#magicHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def magic
  @magic
end

#max_value_lengthHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def max_value_length
  @max_value_length
end

#num_bucketsHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def num_buckets
  @num_buckets
end

#num_entriesHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def num_entries
  @num_entries
end

#reservedHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def reserved
  @reserved
end

#strings_offsetHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def strings_offset
  @strings_offset
end

#versionHMap::HMapHeader? (readonly)

Returns the raw view associated with the load command, or nil if the HMapHeader was created via create.

Returns:

  • (HMap::HMapHeader, nil)

    the raw view associated with the load command, or nil if the HMapHeader was created via create.



73
74
75
# File 'lib/hmap/hmap/hmap_struct.rb', line 73

def version
  @version
end

Instance Method Details

#descriptionObject



98
99
100
101
102
103
104
# File 'lib/hmap/hmap/hmap_struct.rb', line 98

def description
  <<-DESC
    Hash bucket count: #{@num_buckets}
    String table entry count: #{@num_entries}
    Max value length: #{@max_value_length}
  DESC
end

#serializeString

Returns the serialized fields of the mafile.

Returns:

  • (String)

    the serialized fields of the mafile



93
94
95
96
# File 'lib/hmap/hmap/hmap_struct.rb', line 93

def serialize
  format = Utils.specialize_format(FORMAT, SWAPPED)
  [magic, version, reserved, strings_offset, num_entries, num_buckets, max_value_length].pack(format)
end

#to_hObject



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/hmap/hmap/hmap_struct.rb', line 106

def to_h
  {
    'magic' => magic,
    'version' => version,
    'reserved' => reserved,
    'strings_offset' => strings_offset,
    'num_entries' => num_entries,
    'num_buckets' => num_buckets,
    'max_value_length' => max_value_length
  }.merge super
end