Skip to content

Commit

Permalink
WIP get seems ok
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellerstein committed Sep 9, 2024
1 parent b99a1fb commit 1f00c72
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 18 deletions.
42 changes: 39 additions & 3 deletions lattices/src/ght_lazy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,24 @@ where
}

#[sealed]
impl<'a, Head, Rest, Node> ColtNode for var_type!(Option<&'a GhtInner<Head, Node>>, ...Rest)
impl<'a, Head, Head2, Rest, Node> ColtNode for var_type!(Option<&'a GhtInner<Head, GhtInner<Head2, Node>>>, ...Rest)
where
Rest: ColtNode<Head = Head>,
Head: Eq + Hash + Clone,
Head2: Eq + Hash + Clone,
Node: GeneralizedHashTrieNode,
GhtInner<Head, Node>: GeneralizedHashTrieNode<
GhtInner<Head, GhtInner<Head2, Node>>: GeneralizedHashTrieNode<
Head = Rest::Head,
SuffixSchema = Rest::SuffixSchema,
Schema = Rest::Schema,
> + GhtGet,
GhtInner<Head2, Node>: GeneralizedHashTrieNode<Schema = Rest::Schema> + GhtGet,
{
type Schema = Rest::Schema;
type Head = Rest::Head;
type SuffixSchema = Rest::SuffixSchema;
type Get = var_type!(Option<&'a <GhtInner<Head, Node> as GhtGet>::Get>, ...Rest::Get);
type Get =
var_type!(Option<&'a <GhtInner<Head, GhtInner<Head2, Node>> as GhtGet>::Get>, ...Rest::Get);

fn get(&self, head: &GhtKey<Self::Head, Self::Schema>) -> Self::Get {
let (_first, rest) = self;
Expand All @@ -424,6 +427,39 @@ where
}
}
}
#[sealed]
impl<'a, Head, Rest, Schema, ValType> ColtNode for var_type!(Option<&'a GhtInner<Head, GhtLeaf<Schema, ValType>>>, ...Rest)
where
Rest: ColtNode<Head = Head>,
Head: Eq + Hash + Clone,
// GhtInner<Head, GhtInner<Head2, Node>>: GeneralizedHashTrieNode<
// Head = Rest::Head,
// SuffixSchema = Rest::SuffixSchema,
// Schema = Rest::Schema,
// > + GhtGet,
// GhtInner<Head2, Node>: GeneralizedHashTrieNode<Schema = Rest::Schema> + GhtGet,
Schema: Eq + Hash + Clone + PartialEqVariadic,
ValType: Eq + Hash + Clone + PartialEqVariadic,
GhtLeaf<Schema, ValType>: GeneralizedHashTrieNode,
Schema: 'static + Eq + VariadicExt + Hash + Clone + SplitBySuffix<ValType> + PartialEqVariadic,
<Schema as SplitBySuffix<ValType>>::Prefix: Eq + Hash + Clone,
{
type Schema = Rest::Schema;
type Head = Rest::Head;
type SuffixSchema = Rest::SuffixSchema;
type Get = Rest::Get; // Option<&'a <GhtLeaf<Schema, ValType> as GhtGet>::Get>,

fn get(&self, head: &GhtKey<Self::Head, Self::Schema>) -> Self::Get {
let (_first, rest) = self;
Rest::get(rest, head)
// let (_first, rest) = self;
// if let Some(first) = self.0 {
// var_expr!(first.get(head), ...Rest::get(rest, head))
// } else {
// var_expr!(None, ...Rest::get(rest, head))
// }
}
}

#[sealed]
impl<'a, Head, Node> ColtNode for var_type!(Option<&'a GhtInner<Head, Node>>)
Expand Down
18 changes: 3 additions & 15 deletions lattices/src/ght_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,22 +1086,10 @@ mod test {
// println!("Forest after forcing (1, 1, 1, 1): {:?}", forest);

let get_result = ColtNode::get(&forest.as_ref_var().as_option(), &GhtKey::Head(1));
assert_eq!(get_result.len(), forest.len());
assert!(get_result.0.is_none());
assert_eq!(get_result.len(), forest.len() - 1);
let get_result2 = ColtNode::get(&get_result, &GhtKey::Head(1));
assert_eq!(get_result2.len(), forest.len());
assert!(get_result2.0.is_none());
assert!(get_result2.1 .0.is_none());
// // fix up get_result2. Eventually this should be automated
// let (_head2, rest2) = get_result2;
// let (rest_head2, _rest_tail2) = rest2;
// let mut new_head2 = rest_head2;
// new_head2 = None;
// let get_result2 = var_expr!(new_head2, ...rest2);
assert_eq!(get_result2.len(), forest.len() - 2);
let get_result3 = ColtNode::get(&get_result2, &GhtKey::Head(1));
assert_eq!(get_result3.len(), forest.len());
assert!(get_result3.0.is_none());
assert!(get_result3.1 .0.is_none());
assert!(get_result3.1 .1 .0.is_none());
assert_eq!(get_result3.len(), forest.len() - 3);
}
}

0 comments on commit 1f00c72

Please sign in to comment.