Skip to content

Commit 2059d02

Browse files
committed
implement Ord for SegmentKey
1 parent c953114 commit 2059d02

File tree

1 file changed

+21
-5
lines changed
  • libsql-wal/src/storage/backend

1 file changed

+21
-5
lines changed

libsql-wal/src/storage/backend/s3.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,31 @@ pub struct S3Config {
326326
/// map.range(format!("{:019}", u64::MAX - 101)..).next();
327327
/// map.range(format!("{:019}", u64::MAX - 5000)..).next();
328328
/// ```
329-
#[derive(Debug, Clone, Copy)]
329+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
330330
pub struct SegmentKey {
331-
start_frame_no: u64,
332-
end_frame_no: u64,
331+
pub start_frame_no: u64,
332+
pub end_frame_no: u64,
333+
}
334+
335+
impl PartialOrd for SegmentKey {
336+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
337+
match self.start_frame_no.partial_cmp(&other.start_frame_no) {
338+
Some(core::cmp::Ordering::Equal) => {}
339+
ord => return ord,
340+
}
341+
self.end_frame_no.partial_cmp(&other.end_frame_no)
342+
}
343+
}
344+
345+
impl Ord for SegmentKey {
346+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
347+
self.partial_cmp(other).unwrap()
348+
}
333349
}
334350

335351
impl SegmentKey {
336-
fn includes(&self, frame_no: u64) -> bool {
337-
(self.start_frame_no..self.end_frame_no).contains(&frame_no)
352+
pub(crate) fn includes(&self, frame_no: u64) -> bool {
353+
(self.start_frame_no..=self.end_frame_no).contains(&frame_no)
338354
}
339355
}
340356

0 commit comments

Comments
 (0)