Skip to content

Commit

Permalink
revert crossbeam-skiplist for now
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin-j97 committed Dec 20, 2024
1 parent 9113cb4 commit 8175914
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ bytes = ["value-log/bytes"]

[dependencies]
byteorder = "1.5.0"
crossbeam-skiplist = { git = "https://github.com/crossbeam-rs/crossbeam", rev = "45425b032b75d40c8f79be2133eb7d33aaa1d4e4", package = "crossbeam-skiplist" }
crossbeam-skiplist = "0.1.3"
double-ended-peekable = "0.1.0"
enum_dispatch = "0.3.13"
guardian = "1.1.0"
Expand Down
98 changes: 49 additions & 49 deletions src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::{
SeqNo, UserKey, ValueType,
};
use byteorder::{ReadBytesExt, WriteBytesExt};
use crossbeam_skiplist::equivalent::{Comparable, Equivalent};
use std::{
cmp::Reverse,
io::{Read, Write},
Expand Down Expand Up @@ -106,53 +105,54 @@ impl Ord for InternalKey {
}
}

impl Equivalent<InternalKeyRef<'_>> for InternalKey {
fn equivalent(&self, other: &InternalKeyRef<'_>) -> bool {
self.user_key == other.user_key && self.seqno == other.seqno
}
}

impl Comparable<InternalKeyRef<'_>> for InternalKey {
fn compare(&self, other: &InternalKeyRef<'_>) -> std::cmp::Ordering {
(&*self.user_key, Reverse(self.seqno)).cmp(&(other.user_key, Reverse(other.seqno)))
}
}

// REF
// TODO: wait for new crossbeam-skiplist
// TODO: https://github.com/crossbeam-rs/crossbeam/pull/1162
//
// impl Equivalent<InternalKeyRef<'_>> for InternalKey {
// fn equivalent(&self, other: &InternalKeyRef<'_>) -> bool {
// self.user_key == other.user_key && self.seqno == other.seqno
// }
// }

// impl Comparable<InternalKeyRef<'_>> for InternalKey {
// fn compare(&self, other: &InternalKeyRef<'_>) -> std::cmp::Ordering {
// (&*self.user_key, Reverse(self.seqno)).cmp(&(other.user_key, Reverse(other.seqno)))
// }
// }

// Temporary internal key without heap allocation
#[derive(Debug, Eq)]
pub struct InternalKeyRef<'a> {
pub user_key: &'a [u8],
pub seqno: SeqNo,
pub value_type: ValueType,
}

impl<'a> InternalKeyRef<'a> {
// Constructor for InternalKeyRef
pub fn new(user_key: &'a [u8], seqno: u64, value_type: ValueType) -> Self {
InternalKeyRef {
user_key,
seqno,
value_type,
}
}
}

impl<'a> PartialEq for InternalKeyRef<'a> {
fn eq(&self, other: &Self) -> bool {
self.user_key == other.user_key && self.seqno == other.seqno
}
}

impl<'a> PartialOrd for InternalKeyRef<'a> {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl<'a> Ord for InternalKeyRef<'a> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
(&self.user_key, Reverse(self.seqno)).cmp(&(&other.user_key, Reverse(other.seqno)))
}
}
// #[derive(Debug, Eq)]
// pub struct InternalKeyRef<'a> {
// pub user_key: &'a [u8],
// pub seqno: SeqNo,
// pub value_type: ValueType,
// }

// impl<'a> InternalKeyRef<'a> {
// // Constructor for InternalKeyRef
// pub fn new(user_key: &'a [u8], seqno: u64, value_type: ValueType) -> Self {
// InternalKeyRef {
// user_key,
// seqno,
// value_type,
// }
// }
// }

// impl<'a> PartialEq for InternalKeyRef<'a> {
// fn eq(&self, other: &Self) -> bool {
// self.user_key == other.user_key && self.seqno == other.seqno
// }
// }

// impl<'a> PartialOrd for InternalKeyRef<'a> {
// fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
// Some(self.cmp(other))
// }
// }

// impl<'a> Ord for InternalKeyRef<'a> {
// fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// (&self.user_key, Reverse(self.seqno)).cmp(&(&other.user_key, Reverse(other.seqno)))
// }
// }
4 changes: 2 additions & 2 deletions src/memtable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This source code is licensed under both the Apache 2.0 and MIT License
// (found in the LICENSE-* files in the repository)

use crate::key::{InternalKey, InternalKeyRef};
use crate::key::InternalKey;
use crate::segment::block::ItemSize;
use crate::value::{InternalValue, SeqNo, UserValue, ValueType};
use crossbeam_skiplist::SkipMap;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl Memtable {
// abcdef -> 6
// abcdef -> 5
//
let lower_bound = InternalKeyRef::new(
let lower_bound = InternalKey::new(
key,
match seqno {
Some(seqno) => seqno - 1,
Expand Down

0 comments on commit 8175914

Please sign in to comment.