Skip to content

Commit 8d0a98e

Browse files
committed
Redesign transfer trait
1 parent b081c3d commit 8d0a98e

File tree

9 files changed

+162
-176
lines changed

9 files changed

+162
-176
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "skl"
3-
version = "0.22.15"
3+
version = "0.22.16"
44
edition = "2021"
55
rust-version = "1.81.0"
66
repository = "https://github.com/al8n/skl"

src/dynamic/list.rs

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515
ref_counter::RefCounter,
1616
traits::Constructable,
1717
types::{internal::ValuePointer as ValuePointerType, Height, KeyBuilder, ValueBuilder},
18-
FindResult, Header, Inserter, MaybeTombstone, Splice, State, Transformable, Version,
18+
FindResult, Header, Inserter, MaybeTombstone, Splice, Transfer, Version,
1919
};
2020

2121
mod entry;
@@ -318,8 +318,7 @@ where
318318
contains_key: impl Fn(&[u8]) -> bool,
319319
) -> Option<EntryRef<'a, S, C, A, R>>
320320
where
321-
S: State,
322-
S::Data<'a, &'a [u8]>: Transformable<Input = Option<&'a [u8]>>,
321+
S: Transfer<'a, &'a [u8]>,
323322
{
324323
loop {
325324
unsafe {
@@ -337,13 +336,8 @@ where
337336
let pointer = nd.get_value_pointer::<A>();
338337
let value =
339338
nd.get_value_by_value_offset(&self.arena, pointer.value_offset, pointer.value_len);
340-
let ent = EntryRef::from_node_with_pointer(
341-
version,
342-
*nd,
343-
self,
344-
Some(nk),
345-
<S::Data<'a, &'a [u8]> as Transformable>::from_input(value),
346-
);
339+
let ent =
340+
EntryRef::from_node_with_pointer(version, *nd, self, Some(nk), S::from_input(value));
347341
return Some(ent);
348342
}
349343

@@ -359,8 +353,7 @@ where
359353
contains_key: impl Fn(&[u8]) -> bool,
360354
) -> Option<EntryRef<'a, S, C, A, R>>
361355
where
362-
S: State,
363-
S::Data<'a, &'a [u8]>: Transformable<Input = Option<&'a [u8]>>,
356+
S: Transfer<'a, &'a [u8]>,
364357
{
365358
loop {
366359
unsafe {
@@ -390,7 +383,7 @@ where
390383
*nd,
391384
self,
392385
Some(nk),
393-
<S::Data<'a, &'a [u8]> as Transformable>::from_input(value),
386+
S::from_input(value),
394387
);
395388
return Some(ent);
396389
}
@@ -411,13 +404,8 @@ where
411404
let pointer = nd.get_value_pointer::<A>();
412405
let value =
413406
nd.get_value_by_value_offset(&self.arena, pointer.value_offset, pointer.value_len);
414-
let ent = EntryRef::from_node_with_pointer(
415-
version,
416-
*nd,
417-
self,
418-
Some(nk),
419-
<S::Data<'a, &'a [u8]> as Transformable>::from_input(value),
420-
);
407+
let ent =
408+
EntryRef::from_node_with_pointer(version, *nd, self, Some(nk), S::from_input(value));
421409
return Some(ent);
422410
}
423411

@@ -433,8 +421,7 @@ where
433421
contains_key: impl Fn(&[u8]) -> bool,
434422
) -> Option<EntryRef<'a, S, C, A, R>>
435423
where
436-
S: State,
437-
S::Data<'a, &'a [u8]>: Transformable<Input = Option<&'a [u8]>>,
424+
S: Transfer<'a, &'a [u8]>,
438425
{
439426
loop {
440427
unsafe {
@@ -452,13 +439,8 @@ where
452439
let pointer = nd.get_value_pointer::<A>();
453440
let value =
454441
nd.get_value_by_value_offset(&self.arena, pointer.value_offset, pointer.value_len);
455-
let ent = EntryRef::from_node_with_pointer(
456-
version,
457-
*nd,
458-
self,
459-
Some(nk),
460-
<S::Data<'a, &'a [u8]> as Transformable>::from_input(value),
461-
);
442+
let ent =
443+
EntryRef::from_node_with_pointer(version, *nd, self, Some(nk), S::from_input(value));
462444
return Some(ent);
463445
}
464446

@@ -474,8 +456,7 @@ where
474456
contains_key: impl Fn(&[u8]) -> bool,
475457
) -> Option<EntryRef<'a, S, C, A, R>>
476458
where
477-
S: State,
478-
S::Data<'a, &'a [u8]>: Sized + Transformable<Input = Option<&'a [u8]>>,
459+
S: Transfer<'a, &'a [u8]>,
479460
{
480461
loop {
481462
unsafe {
@@ -522,7 +503,7 @@ where
522503
*nd,
523504
self,
524505
Some(nk),
525-
<S::Data<'a, &'a [u8]> as Transformable>::from_input(value),
506+
<S as crate::sealed::Sealed<'_, &[u8]>>::from_input(value),
526507
);
527508
return Some(ent);
528509
}

src/dynamic/list/entry.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{
22
allocator::{Allocator, Node, NodePointer, WithVersion},
33
dynamic::list::SkipList,
44
ref_counter::RefCounter,
5-
Active, MaybeTombstone, State, Transformable, Version,
5+
Active, MaybeTombstone, State, Transfer, Version,
66
};
77
use dbutils::equivalentor::BytesComparator;
88

@@ -104,18 +104,18 @@ where
104104

105105
/// Returns the reference to the value, `None` means the entry is removed.
106106
#[inline]
107-
pub fn value(&self) -> <S::Data<'a, &'a [u8]> as Transformable>::Output
107+
pub fn value(&self) -> S::Data<'a, S::To>
108108
where
109-
S::Data<'a, &'a [u8]>: Transformable,
109+
S: Transfer<'a, &'a [u8]>,
110110
{
111-
self.value.transform()
111+
S::transfer(&self.value)
112112
}
113113

114114
/// Returns `true` if the entry is marked as removed
115115
#[inline]
116116
pub fn tombstone(&self) -> bool
117117
where
118-
S::Data<'a, &'a [u8]>: Transformable,
118+
S: Transfer<'a, &'a [u8]>,
119119
{
120120
!S::validate_data(&self.value)
121121
}
@@ -126,8 +126,7 @@ where
126126
C: BytesComparator,
127127
A: Allocator,
128128
R: RefCounter,
129-
S: State,
130-
S::Data<'a, &'a [u8]>: Sized + Transformable<Input = Option<&'a [u8]>>,
129+
S: Transfer<'a, &'a [u8]>,
131130
{
132131
/// Returns the next entry in the map.
133132
#[inline]

src/dynamic/list/iterator.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{Allocator, EntryRef, NodePointer, RefCounter, SkipList, Version};
2-
use crate::{allocator::Node, State, Transformable};
2+
use crate::{allocator::Node, State, Transfer};
33
use core::{
44
borrow::Borrow,
55
ops::{Bound, RangeBounds},
@@ -155,8 +155,8 @@ where
155155
RC: RefCounter,
156156
Q: ?Sized + Borrow<[u8]>,
157157
R: RangeBounds<Q>,
158-
S: State,
159-
S::Data<'a, &'a [u8]>: Copy + Transformable<Input = Option<&'a [u8]>>,
158+
S: Transfer<'a, &'a [u8]>,
159+
S::Data<'a, &'a [u8]>: Copy,
160160
{
161161
/// Advances to the next position. Returns the key and value if the
162162
/// iterator is pointing at a valid entry, and `None` otherwise.
@@ -384,8 +384,8 @@ where
384384
RC: RefCounter,
385385
Q: ?Sized + Borrow<[u8]>,
386386
R: RangeBounds<Q>,
387-
S: State,
388-
S::Data<'a, &'a [u8]>: Copy + Transformable<Input = Option<&'a [u8]>>,
387+
S: Transfer<'a, &'a [u8]>,
388+
S::Data<'a, &'a [u8]>: Copy,
389389
{
390390
/// Moves the iterator to the highest element whose key is below the given bound.
391391
/// If no such element is found then `None` is returned.
@@ -604,8 +604,8 @@ where
604604
RC: RefCounter,
605605
Q: ?Sized + Borrow<[u8]>,
606606
R: RangeBounds<Q>,
607-
S: State,
608-
S::Data<'a, &'a [u8]>: Copy + Transformable<Input = Option<&'a [u8]>>,
607+
S: Transfer<'a, &'a [u8]>,
608+
S::Data<'a, &'a [u8]>: Copy,
609609
{
610610
type Item = EntryRef<'a, S, C, A, RC>;
611611

@@ -652,8 +652,8 @@ where
652652
RC: RefCounter,
653653
Q: ?Sized + Borrow<[u8]>,
654654
R: RangeBounds<Q>,
655-
S: State,
656-
S::Data<'a, &'a [u8]>: Copy + Transformable<Input = Option<&'a [u8]>>,
655+
S: Transfer<'a, &'a [u8]>,
656+
S::Data<'a, &'a [u8]>: Copy,
657657
{
658658
#[inline]
659659
fn next_back(&mut self) -> Option<Self::Item> {

src/generic/list.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use crate::{
1313
allocator::{Allocator, Deallocator, Meta, Node, NodePointer, Pointer, ValuePointer},
1414
encode_key_size_and_height,
1515
error::Error,
16-
generic::{MaybeTombstone, State},
16+
generic::MaybeTombstone,
1717
internal::RefMeta,
1818
options::CompressionPolicy,
1919
random_height,
2020
ref_counter::RefCounter,
2121
traits::Constructable,
2222
ty_ref,
2323
types::{internal::ValuePointer as ValuePointerType, Height, KeyBuilder, ValueBuilder},
24-
FindResult, Header, Inserter, Splice, Transformable, Version,
24+
FindResult, Header, Inserter, Splice, Transfer, Version,
2525
};
2626

2727
mod entry;
@@ -357,8 +357,7 @@ where
357357
contains_key: impl Fn(&K::Ref<'a>) -> bool,
358358
) -> Option<EntryRef<'a, K, V, S, C, A, R>>
359359
where
360-
S: State,
361-
S::Data<'a, LazyRef<'a, V>>: Transformable<Input = Option<&'a [u8]>>,
360+
S: Transfer<'a, LazyRef<'a, V>>,
362361
{
363362
loop {
364363
unsafe {
@@ -392,8 +391,7 @@ where
392391
contains_key: impl Fn(&K::Ref<'a>) -> bool,
393392
) -> Option<EntryRef<'a, K, V, S, C, A, R>>
394393
where
395-
S: State,
396-
S::Data<'a, LazyRef<'a, V>>: Transformable<Input = Option<&'a [u8]>>,
394+
S: Transfer<'a, LazyRef<'a, V>>,
397395
C: TypeRefEquivalentor<'a, K>,
398396
{
399397
loop {
@@ -461,8 +459,7 @@ where
461459
contains_key: impl Fn(&K::Ref<'a>) -> bool,
462460
) -> Option<EntryRef<'a, K, V, S, C, A, R>>
463461
where
464-
S: State,
465-
S::Data<'a, LazyRef<'a, V>>: Transformable<Input = Option<&'a [u8]>>,
462+
S: Transfer<'a, LazyRef<'a, V>>,
466463
{
467464
loop {
468465
unsafe {
@@ -497,8 +494,7 @@ where
497494
contains_key: impl Fn(&K::Ref<'a>) -> bool,
498495
) -> Option<EntryRef<'a, K, V, S, C, A, R>>
499496
where
500-
S: State,
501-
S::Data<'a, LazyRef<'a, V>>: Transformable<Input = Option<&'a [u8]>>,
497+
S: Transfer<'a, LazyRef<'a, V>>,
502498
C: TypeRefEquivalentor<'a, K>,
503499
{
504500
loop {

src/generic/list/entry.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
allocator::{Allocator, Node, NodePointer, WithVersion},
99
generic::{Active, MaybeTombstone, State},
1010
types::internal::ValuePointer,
11-
Transformable, Version,
11+
Transfer, Version,
1212
};
1313

1414
/// An entry reference of the `SkipMap`.
@@ -35,9 +35,8 @@ where
3535
V: ?Sized + Type,
3636
A: Allocator,
3737
R: RefCounter,
38-
S: State,
39-
S::Data<'a, LazyRef<'a, V>>: Transformable,
40-
<S::Data<'a, LazyRef<'a, V>> as Transformable>::Output: core::fmt::Debug,
38+
S: Transfer<'a, LazyRef<'a, V>>,
39+
S::Data<'a, S::To>: core::fmt::Debug,
4140
{
4241
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
4342
f.debug_struct("EntryRef")
@@ -119,27 +118,27 @@ where
119118

120119
/// Returns the reference to the value, `None` means the entry is removed.
121120
#[inline]
122-
pub fn value(&self) -> <S::Data<'a, LazyRef<'a, V>> as Transformable>::Output
121+
pub fn value(&self) -> S::Data<'a, S::To>
123122
where
124-
S::Data<'a, LazyRef<'a, V>>: Transformable,
123+
S: Transfer<'a, LazyRef<'a, V>>,
125124
{
126-
self.value.transform()
125+
S::transfer(&self.value)
127126
}
128127

129128
/// Returns the value in raw bytes
130129
#[inline]
131-
pub fn raw_value(&self) -> <S::Data<'a, LazyRef<'a, V>> as Transformable>::Input
130+
pub fn raw_value(&self) -> S::Data<'a, &'a [u8]>
132131
where
133-
S::Data<'a, LazyRef<'a, V>>: Transformable,
132+
S: Transfer<'a, LazyRef<'a, V>>,
134133
{
135-
self.value.input()
134+
S::input(&self.value)
136135
}
137136

138137
/// Returns `true` if the entry is marked as removed
139138
#[inline]
140139
pub fn tombstone(&self) -> bool
141140
where
142-
S::Data<'a, LazyRef<'a, V>>: Transformable,
141+
S: Transfer<'a, LazyRef<'a, V>>,
143142
{
144143
!S::validate_data(&self.value)
145144
}
@@ -149,8 +148,7 @@ impl<'a, K, V, S, C, A, R> EntryRef<'a, K, V, S, C, A, R>
149148
where
150149
K: ?Sized + Type,
151150
V: ?Sized + Type,
152-
S: State,
153-
S::Data<'a, LazyRef<'a, V>>: Sized + Transformable<Input = Option<&'a [u8]>>,
151+
S: Transfer<'a, LazyRef<'a, V>>,
154152
A: Allocator,
155153
R: RefCounter,
156154
C: TypeRefComparator<'a, K>,
@@ -226,8 +224,7 @@ impl<'a, K, V, S, C, A, R> EntryRef<'a, K, V, S, C, A, R>
226224
where
227225
K: ?Sized + Type,
228226
V: ?Sized + Type,
229-
S: State,
230-
S::Data<'a, LazyRef<'a, V>>: Transformable<Input = Option<&'a [u8]>>,
227+
S: Transfer<'a, LazyRef<'a, V>>,
231228
A: Allocator,
232229
R: RefCounter,
233230
{
@@ -258,7 +255,7 @@ where
258255
Self {
259256
list,
260257
key,
261-
value: <S::Data<'a, LazyRef<'a, V>> as Transformable>::from_input(raw_value),
258+
value: S::from_input(raw_value),
262259
value_part_pointer: vp,
263260
version: node.version(),
264261
query_version,
@@ -297,7 +294,7 @@ where
297294
Self {
298295
list,
299296
key,
300-
value: <S::Data<'a, LazyRef<'a, V>> as Transformable>::from_input(raw_value),
297+
value: S::from_input(raw_value),
301298
value_part_pointer: pointer,
302299
version: node.version(),
303300
query_version,

0 commit comments

Comments
 (0)