Skip to content

Commit

Permalink
refactor: scope compare
Browse files Browse the repository at this point in the history
  • Loading branch information
ethe committed Jul 17, 2024
1 parent 5246344 commit 8afa5fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
11 changes: 4 additions & 7 deletions src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ impl<K> Scope<K>
where
K: Ord,
{
pub(crate) fn is_between(&self, key: &K) -> bool {
self.min.le(key) && self.max.ge(key)
pub(crate) fn contains(&self, key: &K) -> bool {
&self.min <= key && key <= &self.max
}

pub(crate) fn is_meet(&self, target: &Scope<K>) -> bool {
(self.min.le(&target.min) && self.max.ge(&target.min))
|| (self.min.le(&target.max) && self.max.ge(&target.max))
|| (self.min.le(&target.min)) && self.max.ge(&target.max)
|| (self.min.ge(&target.min)) && self.max.le(&target.max)
pub(crate) fn overlapped(&self, target: &Self) -> bool {
self.contains(&target.min) || self.contains(&target.max)
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ where
key: &TimestampedRef<R::Key>,
) -> Result<Option<RecordBatchEntry<R>>, VersionError<R>> {
for scope in self.level_slice[0].iter().rev() {
if !scope.is_between(key.value()) {
if !scope.contains(key.value()) {
continue;
}
if let Some(entry) = Self::table_query(self, key, &scope.gen).await? {
Expand All @@ -80,7 +80,7 @@ where
continue;
}
let index = Self::scope_search(key.value(), level);
if !level[index].is_between(key.value()) {
if !level[index].contains(key.value()) {
continue;
}
if let Some(entry) = Self::table_query(self, key, &level[index].gen).await? {
Expand Down

0 comments on commit 8afa5fb

Please sign in to comment.