-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadByteTree.h
More file actions
60 lines (51 loc) · 1.9 KB
/
Copy pathThreadByteTree.h
File metadata and controls
60 lines (51 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* @author: Viktor Shishmarev
* @date: 16.10.2025
* @description: Small wrapper around a concurrent SkipList to provide a simple
* key-value API with byte-vector keys and values. Exposes thread-safe put/get.
*/
#pragma once
#include "skiplist.h"
namespace tbt {
class ThreadByteTree {
private:
List skipList;
public:
/*
* Construct a ThreadByteTree backed by a SkipList.
* Parameters:
* - maxLevel: number of levels in the internal skip list (>=1), indexed 0..maxLevel-1.
* - probability: node promotion probability used by the skip list; must be in (0,1).
* Returns:
* - N/A
* Throws:
* - std::invalid_argument if probability is not strictly between 0 and 1 (propagated from List).
* Effects:
* - Initializes the internal skip list with the specified parameters.
*/
ThreadByteTree(std::size_t maxLevel, float probability);
/*
* Insert or update a value by key (synchronous, thread-safe).
* Parameters:
* - key: byte-vector key.
* - value: byte-vector value to associate with key.
* Returns:
* - N/A
* Effects:
* - If the key exists, its value is replaced; otherwise a new entry is created.
* Thread-safety:
* - Safe for concurrent calls; internally serialized for writers.
*/
void put(const ByteVector& key, const ByteVector& value);
/*
* Retrieve a value by key (synchronous, thread-safe).
* Parameters:
* - key: byte-vector key to search for.
* Returns:
* - Associated value if found; otherwise an empty ByteVector.
* Thread-safety:
* - Safe for concurrent calls; multiple readers proceed concurrently.
*/
ByteVector get(const ByteVector& key) const;
};
}