cs431_homework/hash_table/
split_ordered_list.rs1use core::mem::{self, MaybeUninit};
4use core::sync::atomic::AtomicUsize;
5use core::sync::atomic::Ordering::*;
6
7use crossbeam_epoch::{Guard, Owned};
8use cs431::lockfree::list::{Cursor, List, Node};
9
10use super::growable_array::GrowableArray;
11use crate::ConcurrentMap;
12
13#[derive(Debug)]
17pub struct SplitOrderedList<V> {
18 list: List<usize, MaybeUninit<V>>,
22 buckets: GrowableArray<Node<usize, MaybeUninit<V>>>,
24 size: AtomicUsize,
26 count: AtomicUsize,
28}
29
30impl<V> Default for SplitOrderedList<V> {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36impl<V> SplitOrderedList<V> {
37 const LOAD_FACTOR: usize = 2;
39
40 pub fn new() -> Self {
42 Self {
43 list: List::new(),
44 buckets: GrowableArray::new(),
45 size: AtomicUsize::new(2),
46 count: AtomicUsize::new(0),
47 }
48 }
49
50 fn lookup_bucket<'s>(
53 &'s self,
54 index: usize,
55 guard: &'s Guard,
56 ) -> Cursor<'s, usize, MaybeUninit<V>> {
57 todo!()
58 }
59
60 fn find<'s>(
63 &'s self,
64 key: &usize,
65 guard: &'s Guard,
66 ) -> (usize, bool, Cursor<'s, usize, MaybeUninit<V>>) {
67 todo!()
68 }
69
70 fn assert_valid_key(key: usize) {
71 assert!(key.leading_zeros() != 0);
72 }
73}
74
75impl<V> ConcurrentMap<usize, V> for SplitOrderedList<V> {
76 fn lookup<'a>(&'a self, key: &usize, guard: &'a Guard) -> Option<&'a V> {
77 Self::assert_valid_key(*key);
78
79 todo!()
80 }
81
82 fn insert(&self, key: usize, value: V, guard: &Guard) -> Result<(), V> {
83 Self::assert_valid_key(key);
84
85 todo!()
86 }
87
88 fn delete<'a>(&'a self, key: &usize, guard: &'a Guard) -> Result<&'a V, ()> {
89 Self::assert_valid_key(*key);
90
91 todo!()
92 }
93}