pub fn find_row_ids_by_predicate(
        &self,
        predicates: &[Predicate],
        max_results: Option<usize>,
    ) -> Vec<RowId> {
        let max_results = if let Some(max_results) = max_results {
            max_results
        } else {
            self.by_row_id.len()
        };

        if predicates.is_empty() {
            self.find_all_row_ids()
        } else {
            let predicate0 = &predicates[0];
            let mut row_ids = self.find_by_predicate(predicate0);

            for predicate in &predicates[1..] {
                let new_row_ids = row_ids
                    .iter()
                    .filter(|&row_id| self.match_row(*row_id, predicate))
                    .cloned()
                    .collect::<Vec<RowId>>();
                row_ids = new_row_ids;
            }
            if max_results < row_ids.len() {
                let _ = row_ids.drain(max_results..).collect::<Vec<RowId>>();
            }
            row_ids.sort();
            row_ids.dedup();
            row_ids
        }
    }
/// Returns all rows if no predicates are given.
/// The first predicate is evaluated first and should have high selectivity, i. e. evaluate to a
/// small number of rows, to improve execution time. The number of results can be limited with
/// `Some(max_results)`
///
/// # Examples
///
/// ```
/// // Like SQL "select name, value from testdb where name='coche' limit 15"
/// use vdb::{Data, Db, Entry, Predicate, RowId};
/// let mut db = Db::new("test-db");
/// let _id = db.add_row(vec![
///     Entry {
///         name: String::from("set"),
///         value: Db::db_string("es-en"),
///     },
///     Entry {
///         name: String::from("name"),
///         value: Db::db_string("coche"),
///     },
///     Entry {
///         name: String::from("value"),
///         value: Db::db_string("car"),
///     },
/// ]);
/// let predicates = vec![Predicate::new_equal_string("name", "coche")];
/// let row_ids = db.find_row_ids_by_predicate(&predicates, Some(15));
/// assert_eq!(row_ids, [RowId(1)]);
/// assert_eq!(db.entries_from_row_ids(&row_ids, &["name", "value"])[0][0], Entry::new_string("name", "coche"));
/// ```
/// See also find_entries_by_predicate()
Returns all rows if no predicates are given.
The first predicate is evaluated first and should have high selectivity, i. e. evaluate to a
small number of rows, to improve execution time. The number of results can be limited with
`Some(max_results)`
Returns all rows if no predicates are given . The first predicate is evaluated first and should have high selectivity i . e . evaluate to a small number of rows to improve execution time . The number of results can be limited with ` Some ( max_results ) `
pub fn find_row_ids_by_predicate(
        &self,
        predicates: &[Predicate],
        max_results: Option<usize>,
    ) -> Vec<RowId> {
        let max_results = if let Some(max_results) = max_results {
            max_results
        } else {
            self.by_row_id.len()
        };
        if predicates.is_empty() {
            self.find_all_row_ids()
        } else {
            let predicate0 = &predicates[0];
            let mut row_ids = self.find_by_predicate(predicate0);
            for predicate in &predicates[1..] {
                let new_row_ids = row_ids
                    .iter()
                    .filter(|&row_id| self.match_row(*row_id, predicate))
                    .cloned()
                    .collect::<Vec<RowId>>();
                row_ids = new_row_ids;
            }
            if max_results < row_ids.len() {
                let _ = row_ids.drain(max_results..).collect::<Vec<RowId>>();
            }
            row_ids.sort();
            row_ids.dedup();
            row_ids
        }
    }
pub fn find_row_ids_by_predicate ( & self , predicates : & [ Predicate ] , max_results : Option < usize > , ) -> Vec < RowId > { let max_results = if let Some ( max_results ) = max_results { max_results } else { self . by_row_id . len ( ) } ; if predicates . is_empty ( ) { self . find_all_row_ids ( ) } else { let predicate0 = & predicates [ 0 ] ; let mut row_ids = self . find_by_predicate ( predicate0 ) ; for predicate in & predicates [ 1 .. ] { let new_row_ids = row_ids . iter ( ) . filter ( | & row_id | self . match_row ( * row_id , predicate ) ) . cloned ( ) . collect :: < Vec < RowId > > ( ) ; row_ids = new_row_ids ; } if max_results < row_ids . len ( ) { let _ = row_ids . drain ( max_results .. ) . collect :: < Vec < RowId > > ( ) ; } row_ids . sort ( ) ; row_ids . dedup ( ) ; row_ids } }
Returns all rows if no predicates are given.
Returns all rows if no predicates are given .
&self
predicates
&[Predicate]
max_results
Option<usize>
&self
predicates
&[Predicate]
max_results
Option<usize>
examples
```
Like SQL "select name, value from testdb where name='coche' limit 15"
use vdb::{Data, Db, Entry, Predicate, RowId};
let mut db = Db::new("test-db");
let _id = db.add_row(vec![
Entry {
name: String::from("set"),
value: Db::db_string("es-en"),
},
Entry {
name: String::from("name"),
value: Db::db_string("coche"),
},
Entry {
name: String::from("value"),
value: Db::db_string("car"),
},
]);
let predicates = vec![Predicate::new_equal_string("name", "coche")];
let row_ids = db.find_row_ids_by_predicate(&predicates, Some(15));
assert_eq!(row_ids, [RowId(1)]);
assert_eq!(db.entries_from_row_ids(&row_ids, &["name", "value"])[0][0], Entry::new_string("name", "coche"));
```
See also find_entries_by_predicate()
` ` ` Like SQL " select name value from testdb where name = ' coche ' limit 15 " use vdb :: { Data Db Entry Predicate RowId } ; let mut db = Db :: new ( " test - db " ) ; let _id = db . add_row ( vec! [ Entry { name : String :: from ( " set " ) value : Db :: db_string ( " es - en " ) } Entry { name : String :: from ( " name " ) value : Db :: db_string ( " coche " ) } Entry { name : String :: from ( " value " ) value : Db :: db_string ( " car " ) } ] ) ; let predicates = vec! [ Predicate :: new_equal_string ( " name " " coche " ) ] ; let row_ids = db . find_row_ids_by_predicate ( &predicates Some ( 15 )) ; assert_eq! ( row_ids [ RowId ( 1 ) ] ) ; assert_eq! ( db . entries_from_row_ids ( &row_ids & [ " name " " value " ] ) [ 0 ] [ 0 ] Entry :: new_string ( " name " " coche " )) ; ` ` ` See also find_entries_by_predicate ()