2个版本

0.0.2 2023年10月12日
0.0.1 2023年10月6日

#1867数据结构

MIT 许可证

180KB
4.5K SLoC

Fast-Forward 构建状态 覆盖率状态 最新版本

⏩ 快速查询列表。

这是一个非常、非常、 ... 初期的状态。这意味着,这个实现正在寻找一个好的解决方案,并希望任何人都能使用它。API可能会变化很多!请尝试它并给我反馈。

概述

快速前进 是一个用于在(大型)集合(Vec、Slice、Map、...)中查找或过滤项的库。这意味着比 Iterator 或搜索算法更快。它是一个包装器,通过快速查找操作扩展了给定的集合。这个包装器与给定的(原始)集合一样容易使用。

通过使用 Indices 实现了更快的速度。这意味着它不需要触及和比较集合中的每个项目。

Index 有两部分,一个 Key(要搜索的项目)和一个在集合中的 Position(索引)。

索引只读列表(ro::IList)的示例

use fast_forward::{index::UIntIndex, collections::ro::IList};

#[derive(Debug, PartialEq)]
pub struct Car(usize, String);

// created an indexed List with the UIntIndex on the Car property 0.
let l = IList::<UIntIndex, _>::new(|c: &Car| c.0, vec![
                            Car(1, "BMW".into()),
                            Car(2, "VW".into())]);

// idx method pointed to the Car.0 property Index and
// gives access to the `Retriever` object to handle queries, like: contains, get, filter.
assert!(l.idx().contains(&2));
assert!(!l.idx().contains(&2000));

// get a Car with the ID = 2
assert_eq!(l.idx().get(&2).next(), Some(&Car(2, "VW".into())));

// get many Cars with ID = 2 or 1
assert_eq!(
    l.idx().get_many([2, 1]).collect::<Vec<_>>(),
    vec![&Car(2, "VW".into()), &Car(1, "BMW".into())],
);

// the same query with the filter-method
// (which has the disadvantage, that this need a allocation)
assert_eq!(
    l.idx().filter(|f| f.eq(&2) | f.eq(&1)).collect::<Vec<_>>(),
    vec![&Car(1, "BMW".into()), &Car(2, "VW".into())],
);

// you can use the Vec methods too
assert_eq!(2, l.len());

// or you can get MetaData like min and max Key value
use fast_forward::index::store::MetaData;

assert_eq!(1, l.idx().meta().min_key());
assert_eq!(2, l.idx().meta().max_key());

所有支持的项目检索选项,您可以在 crate::collections::Retriever 结构中找到。

索引只读列表(ro::IList)的视图示例

View 类似于数据库视图。这意味着您可以得到您可以看到的项目子集。如果您不想给整个集合提供完全的读取访问权限,这很有用。

所有详细信息请参考 [crate::collections::Retriever::create_view()]

use fast_forward::{index::MapIndex, collections::ro::IList};

#[derive(Debug, PartialEq)]
pub struct Car(usize, String);

// created an indexed List with the MapIndex on the Car property 1.
let l = IList::<MapIndex, _>::new(|c: &Car| c.1.clone(), vec![
                            Car(1, "BMW".into()),
                            Car(2, "VW".into()),
                            Car(3, "Audi".into())]);

// create a view: only for Car Name = "BMW" 0r "Audi"
let view = l.idx().create_view([String::from("BMW"), String::from("Audi")]);

// Car with Name "VW" is NOT in the view
assert!(!view.contains(&String::from("VW")));

// get the Care with the name "Audi"
assert_eq!(
    view.get(&String::from("Audi")).collect::<Vec<_>>(),
    vec![&Car(3, "Audi".into())],
);

// the original list contains of course the Car with ID "VW"
assert!(l.idx().contains(&String::from("VW")));

当前版本:0.0.1

许可协议:MIT

依赖项

~0–435KB