forked from fabianmurariu/mapx2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_test.rs
More file actions
48 lines (39 loc) · 1.58 KB
/
debug_test.rs
File metadata and controls
48 lines (39 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use diskhashmap::byte_store::VecStore;
use diskhashmap::{
types::{Bytes, BytesDecode, BytesEncode},
DiskHashMap,
};
use rustc_hash::FxBuildHasher;
fn main() {
let mut map: DiskHashMap<Bytes, Bytes, VecStore, FxBuildHasher> = DiskHashMap::new();
// Test encoding
let key = b"hello";
let value = b"world";
println!("=== Testing Encoding ===");
let (key_size, key_bytes) = Bytes::bytes_encode(key).unwrap();
let (value_size, value_bytes) = Bytes::bytes_encode(value).unwrap();
println!("Key size: {:?}", key_size);
println!("Key bytes: {:?}", key_bytes.as_ref());
println!("Value size: {:?}", value_size);
println!("Value bytes: {:?}", value_bytes.as_ref());
// Test decoding
println!("\n=== Testing Decoding ===");
let decoded_key = Bytes::bytes_decode_with_size(key_bytes.as_ref(), key_size.unwrap()).unwrap();
let decoded_value =
Bytes::bytes_decode_with_size(value_bytes.as_ref(), value_size.unwrap()).unwrap();
println!("Decoded key: {:?}", decoded_key);
println!("Decoded value: {:?}", decoded_value);
// Test insertion and retrieval
println!("\n=== Testing Map Operations ===");
map.insert(key, value).unwrap();
println!("Inserted key-value pair");
let result = map.get(key).unwrap();
println!("Retrieved result: {:?}", result);
if let Some(retrieved_value) = result {
println!("Retrieved value: {:?}", retrieved_value);
println!("Expected value: {:?}", value);
println!("Match: {}", retrieved_value == value);
} else {
println!("No value retrieved!");
}
}