Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mv fixed_length_vector class to cds/.
- Loading branch information
Showing
7 changed files
with
82 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "fixed_length_vector.h" | ||
|
||
|
||
namespace cds { | ||
unsigned int fixed_length_vector::get_bit_index(unsigned int index) { | ||
return ( | ||
(this->is_rapid && this->rest_size_of_a_cell > 0) ? | ||
index / this->elements_in_a_cell * this->bv.cell_size + index % this->elements_in_a_cell * this->length : | ||
index * this->length | ||
); | ||
} | ||
|
||
fixed_length_vector::fixed_length_vector(unsigned int length, unsigned int size, bool is_rapid) { | ||
this->length = length; | ||
this->is_rapid = is_rapid; | ||
this->elements_in_a_cell = bv.cell_size / this->length; | ||
this->rest_size_of_a_cell = bv.cell_size % this->length; | ||
resize(size); | ||
} | ||
|
||
void fixed_length_vector::resize(unsigned int size) { | ||
this->size = size; | ||
this->bv.resize(this->get_bit_index(this->size)); | ||
} | ||
|
||
unsigned int fixed_length_vector::vector_size() { | ||
return this->bv.vector_size(); | ||
} | ||
|
||
unsigned int fixed_length_vector::read(unsigned int index) { | ||
unsigned int bit_index = this->get_bit_index(index); | ||
|
||
if (this->is_rapid || this->rest_size_of_a_cell == 0) { | ||
return this->bv.bits_read_from_a_cell(bit_index, bit_index + this->length); | ||
} else { | ||
return this->bv.bits_read(bit_index, bit_index + this->length); | ||
} | ||
} | ||
|
||
void fixed_length_vector::write(unsigned int index, unsigned int value) { | ||
unsigned int bit_index = this->get_bit_index(index); | ||
|
||
if (this->is_rapid || this->rest_size_of_a_cell == 0) { | ||
this->bv.bits_write_to_a_cell(bit_index, bit_index + this->length, value); | ||
} else { | ||
this->bv.bits_write(bit_index, bit_index + this->length, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "bit_vector.h" | ||
|
||
|
||
namespace cds { | ||
class fixed_length_vector { | ||
bit_vector bv; | ||
unsigned int elements_in_a_cell; | ||
unsigned int rest_size_of_a_cell; | ||
|
||
unsigned int get_bit_index(unsigned int index); | ||
|
||
public: | ||
unsigned int length; | ||
unsigned int size; | ||
bool is_rapid; | ||
|
||
fixed_length_vector(unsigned int length, unsigned int size = 0, bool is_rapid = false); | ||
|
||
void resize(unsigned int size); | ||
unsigned int vector_size(); | ||
unsigned int read(unsigned int index); | ||
void write(unsigned int index, unsigned int value); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters