Class: StrokeDB::MapVolume
Constant Summary collapse
- HEADER_SIZE =
512
- MAGIC_SIGNATURE =
"\x11\x12\x19\x81"
- VERSION =
"00"
Instance Attribute Summary collapse
-
#first_available_position ⇒ Object
Returns the value of attribute first_available_position.
Instance Method Summary collapse
- #available?(position) ⇒ Boolean
- #bitmap_extension_pace ⇒ Object
- #close! ⇒ Object
- #delete!(position) ⇒ Object
- #elastic_insert!(record) ⇒ Object
- #elastic_read(position) ⇒ Object
- #elastic_write!(position, record) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(options = {}) ⇒ MapVolume
constructor
A new instance of MapVolume.
- #insert!(record) ⇒ Object
- #map_size ⇒ Object
- #path ⇒ Object
- #read(position) ⇒ Object
- #record_size ⇒ Object
- #write!(position, record) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ MapVolume
Returns a new instance of MapVolume.
12 13 14 15 |
# File 'lib/strokedb/volumes/map_volume.rb', line 12 def initialize( = {}) @options = .stringify_keys initialize_file end |
Instance Attribute Details
#first_available_position ⇒ Object
Returns the value of attribute first_available_position.
10 11 12 |
# File 'lib/strokedb/volumes/map_volume.rb', line 10 def first_available_position @first_available_position end |
Instance Method Details
#available?(position) ⇒ Boolean
56 57 58 |
# File 'lib/strokedb/volumes/map_volume.rb', line 56 def available?(position) read_map_byte(position) & (1 << (position % 8)) == 0 end |
#bitmap_extension_pace ⇒ Object
68 69 70 |
# File 'lib/strokedb/volumes/map_volume.rb', line 68 def bitmap_extension_pace @options['bitmap_extension_pace']||8192 end |
#close! ⇒ Object
76 77 78 79 |
# File 'lib/strokedb/volumes/map_volume.rb', line 76 def close! @bitmap_file.close @data_file.close end |
#delete!(position) ⇒ Object
51 52 53 54 |
# File 'lib/strokedb/volumes/map_volume.rb', line 51 def delete!(position) self.first_available_position = -1 increment_available_capacity!(position) end |
#elastic_insert!(record) ⇒ Object
22 23 24 25 |
# File 'lib/strokedb/volumes/map_volume.rb', line 22 def elastic_insert!(record) position = find_first_available_chunk_position((record.size + 4) % 8) elastic_write!(position,record) end |
#elastic_read(position) ⇒ Object
45 46 47 48 49 |
# File 'lib/strokedb/volumes/map_volume.rb', line 45 def elastic_read(position) @data_file.seek(position*record_size) size = @data_file.read(4).unpack('N').first @data_file.read(size) end |
#elastic_write!(position, record) ⇒ Object
34 35 36 37 38 |
# File 'lib/strokedb/volumes/map_volume.rb', line 34 def elastic_write!(position,record) decrement_available_chunk!(position,(record.size + 4) % 8) elastic_write_at_position!(position,record) position end |
#empty? ⇒ Boolean
60 61 62 |
# File 'lib/strokedb/volumes/map_volume.rb', line 60 def empty? read_map == "\x00" * map_size end |
#insert!(record) ⇒ Object
17 18 19 20 |
# File 'lib/strokedb/volumes/map_volume.rb', line 17 def insert!(record) position = find_first_available_position write!(position,record) end |
#map_size ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/strokedb/volumes/map_volume.rb', line 81 def map_size return @map_size if @map_size pos = @bitmap_file.pos @bitmap_file.seek(0,IO::SEEK_END) size = @bitmap_file.pos - HEADER_SIZE @bitmap_file.seek(pos) @map_size = size end |
#path ⇒ Object
72 73 74 |
# File 'lib/strokedb/volumes/map_volume.rb', line 72 def path @options['path'] end |
#read(position) ⇒ Object
40 41 42 43 |
# File 'lib/strokedb/volumes/map_volume.rb', line 40 def read(position) raise InvalidRecordPositionError if available?(position) read_at_position(position) end |
#record_size ⇒ Object
64 65 66 |
# File 'lib/strokedb/volumes/map_volume.rb', line 64 def record_size @options['record_size'] end |
#write!(position, record) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/strokedb/volumes/map_volume.rb', line 27 def write!(position,record) raise InvalidRecordSizeError if record.size != record_size decrement_available_capacity!(position) write_at_position!(position,record) position end |