Class: Tamper::ExistencePack
- Inherits:
-
Pack
- Object
- Pack
- Tamper::ExistencePack
show all
- Defined in:
- lib/tamper/existence_pack.rb
Instance Attribute Summary
Attributes inherited from Pack
#attr_name, #bit_window_width, #bitset, #item_window_width, #max_choices, #max_guid, #meta, #possibilities
Instance Method Summary
collapse
Methods inherited from Pack
build
Constructor Details
Returns a new instance of ExistencePack.
4
5
6
7
8
9
|
# File 'lib/tamper/existence_pack.rb', line 4
def initialize
@output = ''
@current_chunk = ''
@last_guid = 0
@run_counter = 0
end
|
Instance Method Details
#encode(guid) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/tamper/existence_pack.rb', line 18
def encode(guid)
guid_diff = guid.to_i - @last_guid
guid_diff += 1 if @current_chunk.empty? && @output.empty? && guid.to_i > 0
if guid_diff == 1 || guid.to_i == 0 @current_chunk << '1'
@run_counter += 1
elsif guid_diff <= 0 raise ArgumentError, "Error: data was not sorted by GUID (got #{@last_guid}, then #{guid})!"
elsif guid_diff > 40 dump_keep(@current_chunk, @run_counter)
@output += control_code(:skip, guid_diff - 1)
@current_chunk = '1'
@run_counter = 1
else if @run_counter > 40 dump_keep(@current_chunk, @run_counter)
@current_chunk = ''
@run_counter = 0
end
@current_chunk += ('0' * (guid_diff - 1))
@current_chunk << '1'
@run_counter = 1
end
@last_guid = guid.to_i
end
|
#encoding ⇒ Object
14
15
16
|
# File 'lib/tamper/existence_pack.rb', line 14
def encoding
:existence
end
|
#finalize_pack! ⇒ Object
51
52
53
54
55
|
# File 'lib/tamper/existence_pack.rb', line 51
def finalize_pack!
dump_keep(@current_chunk, @run_counter)
raise "Encoding error, #{@output.length} is not an even number of bytes!" if @output.length % 8 > 0
@bitset = Bitset.from_s(@output)
end
|
#initialize_pack!(max_guid, num_items) ⇒ Object
11
12
|
# File 'lib/tamper/existence_pack.rb', line 11
def initialize_pack!(max_guid, num_items)
end
|
#to_h ⇒ Object
57
58
59
60
|
# File 'lib/tamper/existence_pack.rb', line 57
def to_h
{ encoding: encoding,
pack: encoded_bitset }
end
|