@@ -5,6 +5,7 @@ pub use trie::{ALLOW_DUPLICATION, NO_DUPLICATION, DuplicationStrategy, AllowDupl
55use trie:: * ;
66
77use crate :: atom:: * ;
8+ use crate :: matcher:: Bindings ;
89
910use std:: fmt:: Debug ;
1011use std:: borrow:: Cow ;
@@ -142,6 +143,8 @@ impl<'a> Iterator for AtomIter<'a> {
142143 }
143144}
144145
146+ pub type QueryResult = Box < dyn Iterator < Item =Bindings > > ;
147+
145148#[ derive( Default , Debug , Clone , PartialEq , Eq ) ]
146149pub struct AtomIndex < D : DuplicationStrategy = NoDuplication > {
147150 trie : AtomTrie < D > ,
@@ -166,10 +169,9 @@ impl<D: DuplicationStrategy> AtomIndex<D> {
166169
167170 fn atom_token_to_insert_index_key < ' a > ( token : AtomToken < ' a > ) -> InsertKey {
168171 match token {
169- AtomToken :: Atom ( Cow :: Owned ( atom @ Atom :: Variable ( _) ) ) => InsertKey :: Custom ( atom) ,
170- AtomToken :: Atom ( Cow :: Owned ( atom) ) => InsertKey :: Exact ( atom) ,
171172 AtomToken :: StartExpr ( _) => InsertKey :: StartExpr ,
172173 AtomToken :: EndExpr => InsertKey :: EndExpr ,
174+ AtomToken :: Atom ( Cow :: Owned ( atom) ) => InsertKey :: Atom ( atom) ,
173175 _ => panic ! ( "Only owned atoms are expected to be inserted" ) ,
174176 }
175177 }
@@ -182,15 +184,9 @@ impl<D: DuplicationStrategy> AtomIndex<D> {
182184
183185 fn atom_token_to_query_index_key < ' a > ( token : AtomToken < ' a > ) -> QueryKey < ' a > {
184186 match token {
185- AtomToken :: Atom ( Cow :: Borrowed ( atom @ Atom :: Variable ( _) ) ) =>
186- QueryKey :: Custom ( atom) ,
187- AtomToken :: Atom ( Cow :: Borrowed ( atom @ Atom :: Grounded ( gnd) ) )
188- if gnd. as_grounded ( ) . as_match ( ) . is_some ( ) => {
189- QueryKey :: Custom ( atom)
190- } ,
191- AtomToken :: Atom ( Cow :: Borrowed ( atom) ) => QueryKey :: Exact ( atom) ,
192187 AtomToken :: StartExpr ( Some ( atom) ) => QueryKey :: StartExpr ( atom) ,
193188 AtomToken :: EndExpr => QueryKey :: EndExpr ,
189+ AtomToken :: Atom ( Cow :: Borrowed ( atom) ) => QueryKey :: Atom ( atom) ,
194190 _ => panic ! ( "Only borrowed atoms are expected to be queried" ) ,
195191 }
196192 }
@@ -287,6 +283,15 @@ mod test {
287283 assert_eq_bind_no_order ! ( index. query( & Atom :: gnd( Number :: Integer ( 43 ) ) ) , vec![ bind!{ a: Atom :: gnd( Number :: Integer ( 43 ) ) } ] ) ;
288284 }
289285
286+ #[ test]
287+ fn atom_index_query_single_exact_nonhashable ( ) {
288+ let mut index = AtomIndex :: new ( ) ;
289+ index. insert ( Atom :: value ( 42 ) ) ;
290+
291+ assert_eq_bind_no_order ! ( index. query( & Atom :: value( 42 ) ) , vec![ bind!{ } ] ) ;
292+ //assert_eq_bind_no_order!(index.query(&Atom::var("a")), vec![bind!{ a: Atom::value(42) }]);
293+ }
294+
290295 #[ test]
291296 fn atom_index_unique_var_names ( ) {
292297 let mut index = AtomIndex :: new ( ) ;
@@ -313,7 +318,7 @@ mod test {
313318 }
314319
315320 #[ test]
316- fn atom_index_query_expression ( ) {
321+ fn atom_index_query_expression_simple ( ) {
317322 let mut index = AtomIndex :: new ( ) ;
318323 index. insert ( expr ! ( "A" a { Number :: Integer ( 42 ) } a) ) ;
319324
0 commit comments