use crate::key_composer::{KeyComposer, KeyTag, SmallKey, SubkeyComposer};
#[inline]
pub fn meta(kc: &KeyComposer, key: &[u8]) -> SmallKey {
kc.compose_meta_key_stack(KeyTag::SortedIntMeta.as_slice(), key)
}
#[inline]
pub fn item(prefix: &[u8], id: u64) -> SmallKey {
let mut sk = SmallKey::from_slice(prefix);
sk.extend_from_slice(&id.to_be_bytes());
sk
}
#[inline]
pub fn key(kc: &KeyComposer, key: &[u8], id: u64) -> SmallKey {
kc.compose_subkey_stack(KeyTag::SortedIntData.as_slice(), key, &id.to_be_bytes())
}
#[inline]
pub fn prefix(kc: &KeyComposer, key: &[u8]) -> Vec<u8> {
kc.compose_prefix(KeyTag::SortedIntData.as_slice(), key)
}
#[inline]
pub fn prefix_stack(kc: &KeyComposer, key: &[u8]) -> SmallKey {
kc.compose_prefix_stack(KeyTag::SortedIntData.as_slice(), key)
}
#[derive(Debug, Clone)]
pub struct ItemKeyComposer {
composer: SubkeyComposer,
}
impl ItemKeyComposer {
#[inline]
pub fn new(kc: &KeyComposer, key: &[u8]) -> Self {
let p = prefix_stack(kc, key);
Self {
composer: SubkeyComposer::from_slice(&p),
}
}
#[inline(always)]
pub fn key_for_id(&mut self, id: u64) -> &[u8] {
self.composer.compose_sub_u64_be(id)
}
#[inline(always)]
pub fn prefix(&self) -> &[u8] {
self.composer.prefix()
}
}