···
buckets: Vec<CursorBucket>,
) -> StorageResult<(JustCount, Vec<PrefixChild>, Option<Vec<u8>>)> {
-
let prefix_sub = String::sub_prefix(prefix.as_str())?;
let cursor_child = cursor
let decoded: String = db_complete(encoded_bytes)?;
-
let as_sub_prefix = String::sub_prefix(&decoded)?;
-
Ok::<_, EncodingError>(as_sub_prefix)
let mut iters: Vec<NsidCounter> = Vec::with_capacity(buckets.len());
···
let mut iters: Vec<_> = iters
-
it.map(|bla| bla.map(|(nsid, v)| (Child::from_prefix(&nsid, &prefix), v)))
···
-
fn from_prefix(nsid: &Nsid, prefix: &NsidPrefix) -> Self {
if prefix.is_group_of(nsid) {
-
Child::FullNsid(nsid.to_string())
-
.strip_prefix(&format!("{}.", prefix.0))
-
let (segment, _) = suffix.split_once('.').unwrap();
-
Child::ChildPrefix(format!("{}.{segment}", prefix.0))
fn is_before(&self, other: &Child) -> bool {
···
let (n, _) = write.step_rollup()?;
···
buckets: Vec<CursorBucket>,
) -> StorageResult<(JustCount, Vec<PrefixChild>, Option<Vec<u8>>)> {
+
// let prefix_sub_with_null = prefix.as_str().to_string().to_db_bytes()?;
+
let prefix_sub = String::sub_prefix(&prefix.terminated())?; // with trailing dot to ensure full segment match
let cursor_child = cursor
let decoded: String = db_complete(encoded_bytes)?;
+
// TODO: write some tests for cursors, there's probably bugs here
+
let as_sub_prefix_with_null = decoded.to_db_bytes()?;
+
Ok::<_, EncodingError>(as_sub_prefix_with_null)
let mut iters: Vec<NsidCounter> = Vec::with_capacity(buckets.len());
···
let mut iters: Vec<_> = iters
+
let Some(child) = Child::from_prefix(&nsid, &prefix) else {
+
panic!("failed from_prefix: {nsid:?} {prefix:?} (bad iter bounds?)");
···
+
fn from_prefix(nsid: &Nsid, prefix: &NsidPrefix) -> Option<Self> {
if prefix.is_group_of(nsid) {
+
return Some(Child::FullNsid(nsid.to_string()));
+
let suffix = nsid.as_str().strip_prefix(&format!("{}.", prefix.0))?;
+
let (segment, _) = suffix.split_once('.').unwrap();
+
let child_prefix = format!("{}.{segment}", prefix.0);
+
Some(Child::ChildPrefix(child_prefix))
fn is_before(&self, other: &Child) -> bool {
···
let (n, _) = write.step_rollup()?;
+
fn get_prefix_children_lexi_empty() {
+
let (read, _) = fjall_db();
+
NsidPrefix::new("aaa.aaa").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 0);
+
assert_eq!(dids_estimate, 0);
+
assert_eq!(children, vec![]);
+
assert_eq!(cursor, None);
+
fn get_prefix_excludes_exact_collection() -> anyhow::Result<()> {
+
let (read, mut write) = fjall_db();
+
let mut batch = TestBatch::default();
+
write.insert_batch(batch.batch)?;
+
NsidPrefix::new("a.a.a").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 0);
+
assert_eq!(dids_estimate, 0);
+
assert_eq!(children, vec![]);
+
assert_eq!(cursor, None);
+
fn get_prefix_excludes_neighbour_collection() -> anyhow::Result<()> {
+
let (read, mut write) = fjall_db();
+
let mut batch = TestBatch::default();
+
write.insert_batch(batch.batch)?;
+
NsidPrefix::new("a.a.a").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 0);
+
assert_eq!(dids_estimate, 0);
+
assert_eq!(children, vec![]);
+
assert_eq!(cursor, None);
+
fn get_prefix_includes_child_collection() -> anyhow::Result<()> {
+
let (read, mut write) = fjall_db();
+
let mut batch = TestBatch::default();
+
write.insert_batch(batch.batch)?;
+
NsidPrefix::new("a.a").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 1);
+
assert_eq!(dids_estimate, 1);
+
vec![PrefixChild::Collection(NsidCount {
+
nsid: "a.a.a".to_string(),
+
assert_eq!(cursor, None);
+
fn get_prefix_includes_child_prefix() -> anyhow::Result<()> {
+
let (read, mut write) = fjall_db();
+
let mut batch = TestBatch::default();
+
write.insert_batch(batch.batch)?;
+
NsidPrefix::new("a.a").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 1);
+
assert_eq!(dids_estimate, 1);
+
vec![PrefixChild::Prefix(PrefixCount {
+
prefix: "a.a.a".to_string(),
+
assert_eq!(cursor, None);
+
fn get_prefix_merges_child_prefixes() -> anyhow::Result<()> {
+
let (read, mut write) = fjall_db();
+
let mut batch = TestBatch::default();
+
write.insert_batch(batch.batch)?;
+
NsidPrefix::new("a.a").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 2);
+
assert_eq!(dids_estimate, 1);
+
vec![PrefixChild::Prefix(PrefixCount {
+
prefix: "a.a.a".to_string(),
+
assert_eq!(cursor, None);
+
fn get_prefix_exact_and_child_and_prefix() -> anyhow::Result<()> {
+
let (read, mut write) = fjall_db();
+
let mut batch = TestBatch::default();
+
write.insert_batch(batch.batch)?;
+
NsidPrefix::new("a.a.a").unwrap(),
+
OrderCollectionsBy::Lexi { cursor: None },
+
assert_eq!(creates, 2);
+
assert_eq!(dids_estimate, 1);
+
PrefixChild::Collection(NsidCount {
+
nsid: "a.a.a.a".to_string(),
+
PrefixChild::Prefix(PrefixCount {
+
prefix: "a.a.a.a".to_string(),
+
assert_eq!(cursor, None);