pgm-rs

Crates.iopgm-rs
lib.rspgm-rs
version0.1.0
created_at2025-06-08 01:16:37.785267+00
updated_at2025-06-08 01:16:37.785267+00
descriptionA PGM index implementation for sorted u64 keys
homepage
repositoryhttps://github.com/GavinClarke0/pgm-rs
max_upload_size
id1704534
size33,612
Gavin Clarke (GavinClarke0)

documentation

README

PGM-RS


A implementation of the PGM based u64 key indexes described in https://pgm.di.unipi.it/docs/cpp-reference/ in rust with zero copy serialization support. Currently only little endian architectures are supported.

Examples

Standard Copy Version

// Build index from sorted list of u64
let keys: Vec<u64> = (0..10000).step_by(7).collect();
let pgm = PGMIndex::build(&keys, 64).unwrap();

// Serialize index to bytes 
let bytes = pgm.to_bytes().expect("serialize failed");

// Deserialize index from bytes to 
let restored = PGMIndex::from_bytes(&bytes).expect("full deserialize failed");

let key = 9876;
let (lo, hi) = restored.search(key);

// Search original list for index ranges the value may be contained in. 
let found = keys[lo..=hi].binary_search(&key).ok();

Zero Copy Version

// Build index from sorted list of u64
let keys: Vec<u64> = (0..10000).step_by(7).collect();
let pgm = PGMIndex::build(&keys, 64).unwrap();

// Serialize index to bytes 
let bytes = pgm.to_bytes().expect("serialize failed");

let archived = PGMIndex::as_archived(&bytes).expect("zero-copy deserialize failed");
let key = 1000;
let (lo, hi) = archived.search(key);

let key = 9876;
let (lo, hi) = restored.search(key);

// Search original list for index ranges the value may be contained in. 
let found = keys[lo..=hi].binary_search(&key).ok();
Commit count: 3

cargo fmt