Skip to main content

oxgraph_postgres/
search.rs

1//! Search query types.
2
3/// Search predicate over dense node ids (extension hydrates external columns).
4#[derive(Clone, Copy, Debug, PartialEq, Eq)]
5pub enum SearchPredicate {
6    /// Match a single dense node id.
7    NodeId(u32),
8    /// Match nodes whose id is within an inclusive range.
9    NodeIdRange {
10        /// Lower bound.
11        start: u32,
12        /// Upper bound.
13        end: u32,
14    },
15}
16
17impl SearchPredicate {
18    /// Returns whether `node` satisfies this predicate.
19    ///
20    /// # Performance
21    ///
22    /// This method is `O(1)`.
23    #[must_use]
24    pub fn matches(self, node: u32) -> bool {
25        match self {
26            Self::NodeId(expected) => node == expected,
27            Self::NodeIdRange { start, end } => (start..=end).contains(&node),
28        }
29    }
30}