7 #include "../misc/definitions.h"
15 Delta-coded array for storing positive integers.
16 Do not try to encode value 0!
23 const static usint SUPERBLOCK_SIZE = MEGABYTE;
25 // We assume superblock size is divisible by block and sample size.
26 ArrayEncoder(usint block_bytes, usint superblock_size = SUPERBLOCK_SIZE);
29 void addItem(usint value);
34 usint block_size, superblock_bytes;
38 std::list<usint*> array_blocks;
40 usint blocks_in_superblock, current_blocks;
42 std::list<usint*> sample_blocks;
44 usint samples_in_superblock, current_samples;
48 // These are not allowed.
50 ArrayEncoder(const ArrayEncoder&);
51 ArrayEncoder& operator = (const ArrayEncoder&);
58 const static usint INDEX_RATE = 5;
60 Array(std::ifstream& file);
61 Array(ArrayEncoder& encoder);
64 //--------------------------------------------------------------------------
66 void writeTo(std::ofstream& file) const;
68 inline usint getSize() const { return this->items; }
69 inline usint getBlockSize() const { return this->block_size; }
71 usint reportSize() const;
73 //--------------------------------------------------------------------------
78 Iterator(const Array& par);
81 // Returns 0 if the index is invalid.
82 usint getItem(usint index);
85 inline bool hasNext() const
87 return (this->sample + this->cur < this->parent.getSize());
93 usint block, sample, cur, block_items;
95 ReadBuffer buffer, samples;
98 This function returns the sample corresponding to the block the given
99 index might be found in. Parameter is assumed to be valid.
101 usint sampleForIndex(usint index);
103 inline void getSample(usint sample_number)
105 this->block = sample_number;
106 this->sample = this->samples.readItem(sample_number);
108 this->block_items = this->samples.readItem() - this->sample;
109 this->buffer.moveBuffer(this->parent.array + (this->block * this->parent.block_size));
112 // These are not allowed.
114 Iterator(const Iterator&);
115 Iterator& operator = (const Iterator&);
118 //--------------------------------------------------------------------------
125 bool delete_array; // Do we own the array?
127 usint number_of_blocks;
130 Each sample tells how many items are contained in the previous blocks.
135 ReadBuffer* item_index;
139 Build a higher level index for faster queries.
140 The index consists of about (number of samples) / INDEX_RATE pointers.
141 The array cannot be used without the index.
145 // These are not allowed.
148 Array& operator = (const Array&);