diff options
author | Adrian Kummerlaender | 2017-10-07 15:45:37 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2017-10-07 15:45:37 +0200 |
commit | 51a422f161e7e7cc5b1093a12e004165754ec1b9 (patch) | |
tree | 5c23a69b197e614424aba3e14f59be87de6a4fac /example.cc | |
parent | 574e79243648debf57a0d92653bd0df83398e772 (diff) | |
download | DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.tar DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.tar.gz DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.tar.bz2 DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.tar.lz DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.tar.xz DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.tar.zst DictzipQuery-51a422f161e7e7cc5b1093a12e004165754ec1b9.zip |
Introduce IndexFile class
Diffstat (limited to 'example.cc')
-rw-r--r-- | example.cc | 17 |
1 files changed, 7 insertions, 10 deletions
@@ -1,6 +1,5 @@ +#include "index.h" #include "istream/stream.h" -#include "util/base64.h" -#include "util/query.h" #include <string> #include <iostream> @@ -12,7 +11,7 @@ std::string get(const std::string& path, std::size_t offset, std::size_t length) result.resize(length); stream.seekg(offset); - stream.read(result.data(), length); + stream.read(&result[0], length); return result; } @@ -21,14 +20,12 @@ int main(int argc, char** argv) { if ( argc != 2 ) { std::cerr << "Empty query." << std::endl; } else { - // Get index entries of requested word definitions - for ( auto& line : dictzip::get_lines_starting_with("gcide.index", argv[1]) ) { - // Decode location in compressed archive - const std::size_t offset = dictzip::base64_decode(dictzip::get_encoded_offset(line)); - const std::size_t length = dictzip::base64_decode(dictzip::get_encoded_length(line)); + dictzip::IndexFile index("gcide.index"); - // Print the GCIDE definition of _Accession_ - std::cout << get("gcide.dict.dz", offset, length) << std::endl; + // Get index entries of requested word definitions + for ( auto& entry : index.get(argv[1]) ) { + // Print the GCIDE definition + std::cout << get("gcide.dict.dz", entry.offset, entry.length) << std::endl; } } } |