@@ -143,24 +143,29 @@ impl<'a> Iterator for AtomIter<'a> {
143143 }
144144}
145145
146+ /// Iterator over results of the query to the index.
146147pub type QueryResult = Box < dyn Iterator < Item =Bindings > > ;
147148
149+ /// Atom index implementation, parameterized by [DuplicationStrategy].
148150#[ derive( Default , Debug , Clone , PartialEq , Eq ) ]
149151pub struct AtomIndex < D : DuplicationStrategy = NoDuplication > {
150152 trie : AtomTrie < D > ,
151153}
152154
153155impl AtomIndex {
156+ /// New atom index instance using default [NoDuplication] duplication strategy.
154157 pub fn new ( ) -> Self {
155158 Default :: default ( )
156159 }
157160}
158161
159162impl < D : DuplicationStrategy > AtomIndex < D > {
163+ /// New atom index instance passing specific [DuplicationStrategy].
160164 pub fn with_strategy ( _strategy : D ) -> Self {
161165 Default :: default ( )
162166 }
163167
168+ /// Insert atom into index.
164169 pub fn insert ( & mut self , atom : Atom ) {
165170 let key = AtomIter :: from_atom ( atom)
166171 . map ( |token| Self :: atom_token_to_insert_index_key ( token) ) ;
@@ -176,6 +181,7 @@ impl<D: DuplicationStrategy> AtomIndex<D> {
176181 }
177182 }
178183
184+ /// Query atoms which can be unified with `atom` from index.
179185 pub fn query ( & self , atom : & Atom ) -> QueryResult {
180186 let key = AtomIter :: from_ref ( & atom)
181187 . map ( |token| Self :: atom_token_to_query_index_key ( token) ) ;
@@ -191,16 +197,19 @@ impl<D: DuplicationStrategy> AtomIndex<D> {
191197 }
192198 }
193199
200+ /// Remove specific atom from index.
194201 pub fn remove ( & mut self , atom : & Atom ) -> bool {
195202 let key = AtomIter :: from_ref ( & atom)
196203 . map ( |token| Self :: atom_token_to_query_index_key ( token) ) ;
197204 self . trie . remove ( key)
198205 }
199206
207+ /// Iterate via atoms in index.
200208 pub fn iter ( & self ) -> Box < dyn Iterator < Item =Cow < ' _ , Atom > > + ' _ > {
201209 self . trie . unpack_atoms ( )
202210 }
203211
212+ /// Returns [true] if index has no atoms.
204213 pub fn is_empty ( & self ) -> bool {
205214 self . trie . is_empty ( )
206215 }
0 commit comments