Skip to main content

prolly/prolly/
encoding.rs

1//! Encoding types and default constants for Prolly Trees
2
3use serde::{Deserialize, Serialize};
4
5/// Initial (leaf) level from which the prolly tree is built
6pub const INIT_LEVEL: u8 = 0;
7
8/// Default seed for the hash function
9pub const DEFAULT_HASH_SEED: u64 = 0;
10
11/// Default minimum entries before considering chunk boundary
12pub const DEFAULT_MIN_CHUNK_SIZE: usize = 4;
13
14/// Default maximum number of key-value pairs in a node
15pub const DEFAULT_MAX_CHUNK_SIZE: usize = 1024 * 1024;
16
17/// Default chunking factor: 128 = ~0.78% boundary probability
18pub const DEFAULT_CHUNKING_FACTOR: u32 = 128;
19
20/// Encoding type for values
21#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Default)]
22pub enum Encoding {
23    #[default]
24    Raw,
25    Cbor,
26    Json,
27    Custom(String),
28}
29
30#[cfg(test)]
31mod tests {
32    use super::*;
33
34    #[test]
35    fn test_encoding_default() {
36        let encoding = Encoding::default();
37        assert_eq!(encoding, Encoding::Raw);
38    }
39
40    #[test]
41    fn test_encoding_custom() {
42        let encoding = Encoding::Custom("protobuf".to_string());
43        assert_eq!(encoding, Encoding::Custom("protobuf".to_string()));
44    }
45
46    #[test]
47    fn test_constants() {
48        assert_eq!(INIT_LEVEL, 0);
49        assert_eq!(DEFAULT_HASH_SEED, 0);
50        assert_eq!(DEFAULT_MIN_CHUNK_SIZE, 4);
51        assert_eq!(DEFAULT_MAX_CHUNK_SIZE, 1024 * 1024);
52        assert_eq!(DEFAULT_CHUNKING_FACTOR, 128);
53    }
54}