Skip to content

Commit

Permalink
BitPackedArray
Browse files Browse the repository at this point in the history
 - writeFile/readFile
  • Loading branch information
parkchanhee committed Aug 20, 2018
1 parent 3b1578b commit 2262cab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions bit_packed_array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ void BitPackedArray::writeFile(ofstream &fp)
}
}

void BitPackedArray::writeFile(const char *filename)
{
ofstream fp(filename, std::ofstream::binary);
writeFile(fp);
fp.close();
}

void BitPackedArray::writeFile(const string &filename)
{
writeFile(filename.c_str());
}


#define read_fp(x) fp.read((char *)&(x), sizeof((x)))

void BitPackedArray::readFile(ifstream &fp)
Expand Down Expand Up @@ -114,6 +127,18 @@ void BitPackedArray::readFile(ifstream &fp)
cur_ = prev_cnt;
}

void BitPackedArray::readFile(const char *filename)
{
ifstream fp(filename, std::ifstream::binary);
readFile(fp);
fp.close();
}

void BitPackedArray::readFile(const string &filename)
{
readFile(filename.c_str());
}

void BitPackedArray::put(size_t index, TIndexOffU val)
{
assert_lt(index, cur_);
Expand Down
5 changes: 5 additions & 0 deletions bit_packed_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ class BitPackedArray {

void init(size_t max_value);

void writeFile(const char *filename);
void writeFile(const string& filename);
void writeFile(ofstream &fp);

void readFile(const char *filename);
void readFile(const string& filename);
void readFile(ifstream &fp);

void dump() const;
Expand Down

0 comments on commit 2262cab

Please sign in to comment.