Skip to content

Commit

Permalink
remove MergeUpdate #2
Browse files Browse the repository at this point in the history
  • Loading branch information
density215 committed Apr 30, 2024
1 parent 2a2f98d commit 5dbaa8a
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 199 deletions.
2 changes: 1 addition & 1 deletion examples/exact_matches_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
for pfx in pfxs.into_iter() {
println!("insert {}", pfx?);
// let p : rotonda_store::Prefix<u32, PrefixAs> = pfx.into();
tree_bitmap.insert(&pfx.unwrap(), NoMeta::Empty, None)?;
tree_bitmap.insert(&pfx.unwrap(), NoMeta::Empty)?;
}
println!("------ end of inserts\n");
// println!(
Expand Down
52 changes: 26 additions & 26 deletions examples/multi_thread_4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,32 @@ use rotonda_store::prelude::multi::*;
#[derive(Debug, Clone)]
pub struct ComplexPrefixAs(pub Vec<u32>);

impl MergeUpdate for ComplexPrefixAs {
type UserDataIn = ();
type UserDataOut = ();

fn merge_update(
&mut self,
update_record: ComplexPrefixAs,
_: Option<&Self::UserDataIn>,
) -> Result<(), Box<dyn std::error::Error>> {
self.0 = update_record.0;
Ok(())
}

fn clone_merge_update(
&self,
update_meta: &Self,
_: Option<&Self::UserDataIn>,
) -> Result<(Self, Self::UserDataOut), Box<dyn std::error::Error>>
where
Self: std::marker::Sized,
{
let mut new_meta = update_meta.0.clone();
new_meta.push(self.0[0]);
Ok((ComplexPrefixAs(new_meta), ()))
}
}
// impl MergeUpdate for ComplexPrefixAs {
// type UserDataIn = ();
// type UserDataOut = ();

// fn merge_update(
// &mut self,
// update_record: ComplexPrefixAs,
// _: Option<&Self::UserDataIn>,
// ) -> Result<(), Box<dyn std::error::Error>> {
// self.0 = update_record.0;
// Ok(())
// }

// fn clone_merge_update(
// &self,
// update_meta: &Self,
// _: Option<&Self::UserDataIn>,
// ) -> Result<(Self, Self::UserDataOut), Box<dyn std::error::Error>>
// where
// Self: std::marker::Sized,
// {
// let mut new_meta = update_meta.0.clone();
// new_meta.push(self.0[0]);
// Ok((ComplexPrefixAs(new_meta), ()))
// }
// }

impl std::fmt::Display for ComplexPrefixAs {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion examples/real_single_thread_24.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

print!("{}-", pfx_int);
let asn: u32 = rng.gen();
match tree_bitmap.insert(&pfx.unwrap(), PrefixAs(asn), None) {
match tree_bitmap.insert(&pfx.unwrap(), PrefixAs(asn)) {
Ok(_) => {}
Err(e) => {
println!("{}", e);
Expand Down
4 changes: 2 additions & 2 deletions src/local_array/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use epoch::Guard;
use crate::af::AddressFamily;
use crate::local_array::store::atomic_types::{NodeBuckets, PrefixBuckets};
use inetnum::addr::Prefix;
use crate::prefix_record::{MergeUpdate, Meta, PublicRecord};
use crate::prefix_record::{Meta, PublicRecord};

use crate::QueryResult;

Expand All @@ -20,7 +20,7 @@ use super::store::atomic_types::StoredPrefix;
impl<'a, AF, M, NB, PB> TreeBitMap<AF, M, NB, PB>
where
AF: AddressFamily,
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<AF>,
PB: PrefixBuckets<AF, M>,
{
Expand Down
2 changes: 1 addition & 1 deletion src/local_array/store/custom_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ use std::marker::PhantomData;
use crate::{local_array::tree::*, stats::CreatedNodes};
use crate::{
local_array::{bit_span::BitSpan, store::errors::PrefixStoreError},
prefix_record::{MergeUpdate, PublicRecord},
prefix_record::PublicRecord,
};

// use crate::prefix_record::InternalPrefixRecord;
Expand Down
4 changes: 2 additions & 2 deletions src/local_array/store/default_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::prelude::multi::*;
struct DefaultStore;

impl<
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<IPv4>,
PB: PrefixBuckets<IPv4, M>
> fmt::Display for CustomAllocStorage<IPv4, M, NB, PB>
Expand All @@ -26,7 +26,7 @@ impl<
}

impl<
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<IPv6>,
PB: PrefixBuckets<IPv6, M>
> fmt::Display for CustomAllocStorage<IPv6, M, NB, PB>
Expand Down
10 changes: 5 additions & 5 deletions src/local_array/tree.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::prefix_record::{MergeUpdate, Meta, PublicRecord};
use crate::prefix_record::{Meta, PublicRecord};
use crossbeam_epoch::{self as epoch};
use log::{error, log_enabled, trace};

Expand Down Expand Up @@ -360,7 +360,7 @@ impl std::fmt::Display for StrideType {

pub struct TreeBitMap<
AF: AddressFamily,
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<AF>,
PB: PrefixBuckets<AF, M>,
> {
Expand All @@ -370,7 +370,7 @@ pub struct TreeBitMap<
impl<
'a,
AF: AddressFamily,
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<AF>,
PB: PrefixBuckets<AF, M>,
> TreeBitMap<AF, M, NB, PB>
Expand Down Expand Up @@ -659,7 +659,7 @@ impl<

impl<
AF: AddressFamily,
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<AF>,
PB: PrefixBuckets<AF, M>,
> Default for TreeBitMap<AF, M, NB, PB>
Expand All @@ -673,7 +673,7 @@ impl<
#[cfg(feature = "cli")]
impl<
AF: AddressFamily,
M: Meta + MergeUpdate,
M: Meta,
NB: NodeBuckets<AF>,
PB: PrefixBuckets<AF, M>,
> std::fmt::Display for TreeBitMap<AF, M, NB, PB>
Expand Down
4 changes: 2 additions & 2 deletions src/local_vec/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
macro_rules! match_node_for_strides_with_local_vec {
(
$self: ident;
$user_data: ident;
// $user_data: ident;
$nibble_len: expr;
$nibble: expr;
$is_last_stride: expr;
Expand Down Expand Up @@ -83,7 +83,7 @@ macro_rules! match_node_for_strides_with_local_vec {
// so we can return from here.
// If we don't then we cannot move pfx.meta into the update_prefix_meta function,
// since the compiler can't figure out that it will happen only once.
$self.update_prefix_meta(pfx_idx, $pfx.meta, $user_data)?;
$self.update_prefix_meta(pfx_idx, $pfx.meta)?;
$self.store.update_node($cur_i,SizedStrideNode::$variant(current_node));

// let _default_val = std::mem::replace(
Expand Down
6 changes: 3 additions & 3 deletions src/local_vec/storage_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::prefix_record::InternalPrefixRecord;
use crate::local_vec::tree::*;

use crate::af::AddressFamily;
use crate::prefix_record::MergeUpdate;
// use crate::prefix_record::MergeUpdate;

use std::fmt::Debug;
use std::io::{Error, ErrorKind};
Expand All @@ -20,7 +20,7 @@ where
{
type NodeType;
type AF: AddressFamily;
type Meta: crate::prefix_record::Meta + MergeUpdate;
type Meta: crate::prefix_record::Meta;

fn init(
start_node: Option<SizedStrideNode<Self::AF, Self::NodeType>>,
Expand Down Expand Up @@ -98,7 +98,7 @@ pub(crate) struct InMemStorage<
pub prefixes: Vec<InternalPrefixRecord<AF, Meta>>,
}

impl<AF: AddressFamily, Meta: crate::prefix_record::Meta + MergeUpdate>
impl<AF: AddressFamily, Meta: crate::prefix_record::Meta>
StorageBackend for InMemStorage<AF, Meta>
{
type NodeType = InMemNodeId;
Expand Down
18 changes: 6 additions & 12 deletions src/local_vec/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{MatchOptions, Stats, Strides};

use crate::af::{IPv4, IPv6};
use inetnum::addr::Prefix;
use crate::prefix_record::MergeUpdate;

use super::query::PrefixId;
use super::tree::SizedStrideNode;
Expand All @@ -16,15 +15,12 @@ use super::tree::SizedStrideNode;
/// Can be used in multi-threaded contexts by wrapping it in a `Arc<Mutex<_>>`.
/// Be aware that this is undesirable in cases with high contention.
/// Use cases with high contention are best served by the [`crate::MultiThreadedStore`].
pub struct Store<M: crate::prefix_record::Meta>
where
M: MergeUpdate,
{
pub struct Store<M: crate::prefix_record::Meta> {
v4: TreeBitMap<InMemStorage<IPv4, M>>,
v6: TreeBitMap<InMemStorage<IPv6, M>>,
}

impl<M: crate::prefix_record::Meta + MergeUpdate> Store<M> {
impl<M: crate::prefix_record::Meta> Store<M> {
pub fn new(v4_strides: Vec<u8>, v6_strides: Vec<u8>) -> Self {
Store {
v4: TreeBitMap::new(v4_strides),
Expand All @@ -33,7 +29,7 @@ impl<M: crate::prefix_record::Meta + MergeUpdate> Store<M> {
}
}

impl<'a, M: crate::prefix_record::Meta + MergeUpdate> Store<M> {
impl<'a, M: crate::prefix_record::Meta> Store<M> {
pub fn match_prefix(
&'a self,
search_pfx: &Prefix,
Expand All @@ -55,24 +51,22 @@ impl<'a, M: crate::prefix_record::Meta + MergeUpdate> Store<M> {
&mut self,
prefix: &Prefix,
meta: M,
user_data: Option<&<M as MergeUpdate>::UserDataIn>,
// user_data: Option<&<M>::UserDataIn>,
) -> Result<(), std::boxed::Box<dyn std::error::Error>> {
match prefix.addr() {
std::net::IpAddr::V4(addr) => {
self.v4.insert(InternalPrefixRecord::new_with_meta(
addr.into(),
prefix.len(),
meta,
),
user_data)
))
}
std::net::IpAddr::V6(addr) => {
self.v6.insert(InternalPrefixRecord::new_with_meta(
addr.into(),
prefix.len(),
meta,
),
user_data)
))
}
}
}
Expand Down
54 changes: 27 additions & 27 deletions src/local_vec/tests/full_table_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,32 @@ mod full_table {
#[derive(Debug, Clone)]
pub struct ComplexPrefixAs(pub Vec<u32>);

impl MergeUpdate for ComplexPrefixAs {
type UserDataIn = ();
type UserDataOut = ();

fn merge_update(
&mut self,
update_record: ComplexPrefixAs,
_: Option<&Self::UserDataIn>,
) -> Result<(), Box<dyn std::error::Error>> {
self.0 = update_record.0;
Ok(())
}

fn clone_merge_update(
&self,
update_meta: &Self,
_: Option<&Self::UserDataIn>,
) -> Result<(Self, Self::UserDataOut), Box<dyn std::error::Error>>
where
Self: std::marker::Sized,
{
let mut new_meta = update_meta.0.clone();
new_meta.push(self.0[0]);
Ok((ComplexPrefixAs(new_meta), ()))
}
}
// impl MergeUpdate for ComplexPrefixAs {
// type UserDataIn = ();
// type UserDataOut = ();

// fn merge_update(
// &mut self,
// update_record: ComplexPrefixAs,
// _: Option<&Self::UserDataIn>,
// ) -> Result<(), Box<dyn std::error::Error>> {
// self.0 = update_record.0;
// Ok(())
// }

// fn clone_merge_update(
// &self,
// update_meta: &Self,
// _: Option<&Self::UserDataIn>,
// ) -> Result<(Self, Self::UserDataOut), Box<dyn std::error::Error>>
// where
// Self: std::marker::Sized,
// {
// let mut new_meta = update_meta.0.clone();
// new_meta.push(self.0[0]);
// Ok((ComplexPrefixAs(new_meta), ()))
// }
// }

impl std::fmt::Display for ComplexPrefixAs {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down Expand Up @@ -99,7 +99,7 @@ mod full_table {

let inserts_num = pfxs.len();
for pfx in pfxs.into_iter() {
match tree_bitmap.insert(&pfx.prefix, pfx.meta, None) {
match tree_bitmap.insert(&pfx.prefix, pfx.meta) {
Ok(_) => {}
Err(e) => {
println!("{}", e);
Expand Down
4 changes: 2 additions & 2 deletions src/local_vec/tests/more_specifics_single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ mod tests {
];

for pfx in pfxs.iter() {
tree_bitmap.insert(pfx, PrefixAs(666), None)?;
tree_bitmap.insert(pfx, PrefixAs(666))?;
}
println!("------ end of inserts\n");

Expand Down Expand Up @@ -102,7 +102,7 @@ mod tests {
];

for pfx in pfxs.iter() {
tree_bitmap.insert(&pfx.unwrap(), PrefixAs(666), None)?;
tree_bitmap.insert(&pfx.unwrap(), PrefixAs(666))?;
}
println!("------ end of inserts\n");

Expand Down
Loading

0 comments on commit 5dbaa8a

Please sign in to comment.