const hashtable_database_reader::get_result hashtable_database_reader::get( const hash_digest& key_hash) const { uint64_t bucket_index = remainder(key_hash.data(), writer_.buckets()); BITCOIN_ASSERT(bucket_index < writer_.buckets()); uint64_t record_offset = read_record_offset(file_.data(), bucket_index); const uint64_t header_size = 24 + writer_.buckets() * 8; const uint8_t* all_records_begin = file_.data() + header_size; const uint8_t* all_records_end = all_records_begin + writer_.records_size(); const uint8_t* record_begin = all_records_begin + record_offset; // We don't know the end of a record, so we use the end of all records // for the deserializer. // We will be jumping around the records since it's a chained // list per bucket. // Begin iterating the list. while (true) { auto deserial = make_deserializer(record_begin, all_records_end); const hash_digest current_hash = deserial.read_hash(); uint64_t value_size = deserial.read_variable_uint(); if (current_hash != key_hash) { // Move to next record in bucket. // Skip the transaction data. deserial.set_iterator(deserial.iterator() + value_size); uint64_t next_record = deserial.read_8_bytes(); if (next_record == record_doesnt_exist) return {nullptr, nullptr}; record_begin = all_records_begin + next_record; continue; } // We have the record! return {deserial.iterator(), deserial.iterator() + value_size}; } BITCOIN_ASSERT_MSG(false, "Broke out of unbreakable loop!"); return {nullptr, nullptr}; }
std::string read_string() { uint64_t string_size = read_variable_uint(); return read_fixed_string(string_size); }