Add fetchSublist method to BinaryTable for improved data retrieval
This commit is contained in:
105
cpp/debug/debug_step_by_step.cpp
Normal file
105
cpp/debug/debug_step_by_step.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include "../binary_table.h"
|
||||
|
||||
void dumpFile(const std::string& filename) {
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<uint8_t> data(size);
|
||||
file.read(reinterpret_cast<char*>(data.data()), size);
|
||||
|
||||
std::cout << "File size: " << size << " bytes" << std::endl;
|
||||
for (size_t i = 0; i < std::min(size, size_t(80)); i++) {
|
||||
if (i % 16 == 0) std::cout << std::hex << i << ": ";
|
||||
std::cout << std::hex << std::setfill('0') << std::setw(2) << (int)data[i] << " ";
|
||||
if (i % 16 == 15) std::cout << std::endl;
|
||||
}
|
||||
if (size % 16 != 0) std::cout << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
using namespace bt;
|
||||
|
||||
const std::string filename = "debug_step.bin";
|
||||
if (std::filesystem::exists(filename)) {
|
||||
std::filesystem::remove(filename);
|
||||
}
|
||||
|
||||
BinaryTable table(filename);
|
||||
table.initialize();
|
||||
|
||||
std::cout << "=== Step-by-step Address Table Debug ===\n" << std::endl;
|
||||
|
||||
std::cout << "After initialize():" << std::endl;
|
||||
dumpFile(filename);
|
||||
|
||||
std::cout << "\n1. Before storing key1:" << std::endl;
|
||||
// Try reading the address table header
|
||||
{
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
int64_t addr;
|
||||
file.read(reinterpret_cast<char*>(&addr), 8);
|
||||
std::cout << "Address table pointer: " << addr << std::endl;
|
||||
}
|
||||
|
||||
std::cout << "\n2. Storing key1..." << std::endl;
|
||||
table.set<int32_t>("key1", 100);
|
||||
|
||||
std::cout << "After storing key1:" << std::endl;
|
||||
dumpFile(filename);
|
||||
|
||||
// Try reading the address table
|
||||
{
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
int64_t addr;
|
||||
file.read(reinterpret_cast<char*>(&addr), 8);
|
||||
std::cout << "Address table pointer: " << addr << std::endl;
|
||||
|
||||
if (addr != -1) {
|
||||
file.seekg(addr);
|
||||
uint8_t type;
|
||||
int32_t count;
|
||||
file.read(reinterpret_cast<char*>(&type), 1);
|
||||
file.read(reinterpret_cast<char*>(&count), 4);
|
||||
std::cout << "Address table type: " << (int)type << ", count: " << count << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\n3. Storing key2..." << std::endl;
|
||||
table.set<int32_t>("key2", 200);
|
||||
|
||||
std::cout << "After storing key2:" << std::endl;
|
||||
dumpFile(filename);
|
||||
|
||||
// Try reading the address table again
|
||||
{
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
int64_t addr;
|
||||
file.read(reinterpret_cast<char*>(&addr), 8);
|
||||
std::cout << "Address table pointer: " << addr << std::endl;
|
||||
|
||||
if (addr != -1) {
|
||||
file.seekg(addr);
|
||||
uint8_t type;
|
||||
int32_t count;
|
||||
file.read(reinterpret_cast<char*>(&type), 1);
|
||||
file.read(reinterpret_cast<char*>(&count), 4);
|
||||
std::cout << "Address table type: " << (int)type << ", count: " << count << std::endl;
|
||||
|
||||
// Read the entries
|
||||
for (int32_t i = 0; i < count && i < 5; i++) {
|
||||
int64_t keyHash, valueAddr;
|
||||
file.read(reinterpret_cast<char*>(&keyHash), 8);
|
||||
file.read(reinterpret_cast<char*>(&valueAddr), 8);
|
||||
std::cout << "Entry " << i << ": hash=" << keyHash << ", addr=" << valueAddr << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user