Skip to content

Commit

Permalink
fix Argument
Browse files Browse the repository at this point in the history
  • Loading branch information
shuoli84 committed Aug 19, 2024
1 parent 2a05168 commit 9f2e5b9
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ assert!(map.get(&2).is_none());

### Order statistic tree

Or enhaunced with `Argument`
Or enhanced with `Augmentation`

```rust
use sweep_bptree::BPlusTreeMap;
use sweep_bptree::augment::count::Count;

// use Count as Argument to create a order statistic tree
// use Count to create an order statistic tree
let mut map = BPlusTreeMap::<i32, i32, Count>::new();
map.insert(1, 2);
map.insert(2, 3);
Expand All @@ -57,14 +57,14 @@ assert_eq!(map.get_by_augmentation(1), Some((&2, &3)));

// get the offset for key

// 0 does not exists
// 0 does not exist
assert_eq!(map.rank_by_augmentation(&0), Err(0));

assert_eq!(map.rank_by_augmentation(&1), Ok(0));
assert_eq!(map.rank_by_augmentation(&2), Ok(1));
assert_eq!(map.rank_by_augmentation(&3), Ok(2));

// 4 does not exists
// 4 does not exist
assert_eq!(map.rank_by_augmentation(&4), Err(3));
```

Expand Down
16 changes: 8 additions & 8 deletions examples/date_statistic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This examples shows how to use Argument to make date based statistics easy
//! This examples shows how to use Augmentation to make date based statistics easy
use std::cmp::Ordering;

use sweep_bptree::{
Expand Down Expand Up @@ -40,13 +40,13 @@ impl CountForYear {
}
}

impl<V> DescendVisit<Date, V, DateStatisticArgument> for CountForYear {
impl<V> DescendVisit<Date, V, DateStatistic> for CountForYear {
type Result = usize;

fn visit_inner(
&mut self,
_keys: &[Date],
augmentations: &[DateStatisticArgument],
augmentations: &[DateStatistic],
) -> DescendVisitResult<Self::Result> {
// Need to handle following cases:
// 1. if the year is at min boundary, then we can return it
Expand Down Expand Up @@ -119,15 +119,15 @@ struct DateStatisticEntry {
counter: Counter,
}

/// This Argument keeps track of item count for child node.
/// This Augmentation keeps track of item count for child node.
#[derive(Clone, Debug, Default)]
struct DateStatisticArgument {
struct DateStatistic {
min: DateStatisticEntry,
max: DateStatisticEntry,
}

/// How the Argument is aggregated from children
impl Augmentation<Date> for DateStatisticArgument {
/// How the `DateStatistic` aggregated from children
impl Augmentation<Date> for DateStatistic {
/// aggregate for inner
fn from_inner(_keys: &[Date], augmentations: &[Self]) -> Self {
let mut augmentation_iter = augmentations.iter();
Expand Down Expand Up @@ -246,7 +246,7 @@ impl Augmentation<Date> for DateStatisticArgument {
}

fn main() {
let mut tree = BPlusTreeMap::<Date, (), DateStatisticArgument>::new();
let mut tree = BPlusTreeMap::<Date, (), DateStatistic>::new();

for year in 2011..2021 {
for month in 1..13 {
Expand Down
4 changes: 2 additions & 2 deletions src/augment/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::Key;

use super::{Augmentation, RankAugmentation, SearchAugmentation};

/// Argument to count the number of groups in a set of keys
/// Augmentation to count the number of groups in a set of keys
/// Note, the group must be ordered
/// This Argument basically provides two capabilities:
/// This Augmentation basically provides two capabilities:
/// 1. Get the group count
/// 2. Query inside group by offset
#[derive(Clone, Debug)]
Expand Down
6 changes: 3 additions & 3 deletions src/augment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use crate::Key;
pub mod count;
pub mod group;

/// Argument trait, it is used to store augmentation, like 'size'
/// Augmentation trait, it is used to store augmentation, like 'size'
/// NOTE: Since the lib has no control on how value changes, so augment only calculated from keys
/// e.g: Map<i64, Arc<Mutex<i64>>
pub trait Augmentation<K: Key>: Clone + Default {
fn is_zst() -> bool {
false
}

/// create a new Argumentation from inner node and its augment
/// create a new Augmentation from inner node and its augment
/// e.g: take size as example.
/// the root node's augment is created from its children's augment and keys
/// the inner node with height 1's is created from leaf's keys
Expand All @@ -20,7 +20,7 @@ pub trait Augmentation<K: Key>: Clone + Default {
/// leaf[0] 5 leaf[1] 4 leaf[2] 3 leaf[2] 2
fn from_inner(keys: &[K], augmentations: &[Self]) -> Self;

/// create a new Argumentation from leaf node's key
/// create a new Augmentation from leaf node's key
fn from_leaf(keys: &[K]) -> Self;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tree/inner_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct InnerNode<K: Key, A: Augmentation<K>> {

slot_key: [MaybeUninit<K>; N],
child_id: [MaybeUninit<NodeId>; C],
/// The Argument for each Child
/// The Augmentation for each Child
augmentations: [MaybeUninit<A>; C],
}

Expand Down
2 changes: 1 addition & 1 deletion src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ pub trait NodeStore: Default {
/// Value type for the tree
type V;

/// The Argument type
/// The Augmentation type
type Augmentation: Augmentation<Self::K>;

/// Get the max number of keys inner node can hold
Expand Down

0 comments on commit 9f2e5b9

Please sign in to comment.