-
Notifications
You must be signed in to change notification settings - Fork 294
/
bufferedMQF.h
123 lines (83 loc) · 3.38 KB
/
bufferedMQF.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef bufferedMQF_H
#define bufferedMQF_H
#include <inttypes.h>
#include <stdbool.h>
#include <pthread.h>
#include "gqf.h"
#include "onDiskMQF.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef class bufferedMQF {
public:
QF* memoryBuffer;
onDiskMQF_Namespace::onDiskMQF* disk;
bufferedMQF(){
memoryBuffer=new QF();
//disk=new onDiskMQF_Namespace::onDiskMQF();
}
~bufferedMQF()
{
delete memoryBuffer;
delete disk;
}
} bufferedMQF;
void bufferedMQF_init(bufferedMQF *qf, uint64_t nslots_buffer ,uint64_t nslots, uint64_t key_bits, uint64_t value_bits,uint64_t fixed_counter_size,const char *path);
void bufferedMQF_reset(bufferedMQF *qf);
void bufferedMQF_destroy(bufferedMQF *qf);
void bufferedMQF_copy(bufferedMQF *dest, bufferedMQF *src);
void bufferedMQF_syncBuffer(bufferedMQF *qf);
/* Increment the counter for this key/value pair by count. */
bool bufferedMQF_insert(bufferedMQF *qf, uint64_t key, uint64_t count,
bool lock, bool spin);
/* Remove count instances of this key/value combination. */
bool bufferedMQF_remove(QF *qf, uint64_t hash, uint64_t count, bool lock=false, bool spin=false);
/*!
@breif Add Tag to item.
@param Qf* qf : pointer to the Filter
@param uint64_t key : hash of the item to be insertedItems
@param uint64_t tag: tag to be added
@param bool lock: For Multithreading, Lock the slot used by the current thread so that other threads can't change the value
@param bool spin: For Multithreading, If there is a lock on the target slot. wait until the lock is freed and insert the count.
@return bool: True if the item is inserted correctly.
*/
uint64_t bufferedMQF_add_tag(const QF *qf, uint64_t key, uint64_t tag, bool lock=false, bool spin=false);
/*!
@breif Return the tag associated with a given item.
@param Qf* qf : pointer to the Filter.
@param uint64_t key : hash of the item.
@return uint64_t the tag associated with the input key.
*/
uint64_t bufferedMQF_get_tag(const QF *qf, uint64_t key);
/*!
@breif delete the tag associated with a given item.
@param Qf* qf : pointer to the Filter.
@param uint64_t key : hash of the item.
@return bool: Returns true if the item is removed successfully.
*/
uint64_t bufferedMQF_remove_tag(const QF *qf, uint64_t key, bool lock=false, bool spin=false);
/* Return the number of times key has been inserted, with any value,
into qf. */
uint64_t bufferedMQF_count_key(const bufferedMQF *qf, uint64_t key);
void bufferedMQF_BatchQuery( bufferedMQF* qf,QF* input);
/* For debugging */
void bufferedMQF_dump(const bufferedMQF *);
/* write data structure of to the disk */
void bufferedMQF_serialize(const bufferedMQF *qf, const char *filename);
/* read data structure off the disk */
void bufferedMQF_deserialize(bufferedMQF *qf, const char *filename);
/* mmap the QF from disk. */
void bufferedMQF_read(bufferedMQF *qf, const char *path);
/* merge two QFs into the third one. */
//void bufferedMQF_merge(bufferedMQF *bufferedMQFa, bufferedMQF *bufferedMQFb, QF *qfc);
/* merge multiple QFs into the final QF one. */
//void qf_multi_merge(QF *qf_arr[], int nqf, QF *qfr);
/* find cosine similarity between two QFs. */
// uint64_t qf_inner_product(QF *qfa, QF *qfb);
/* magnitude of a QF. */
//uint64_t qf_magnitude(QF *qf);
int bufferedMQF_space(bufferedMQF *qf);
#ifdef __cplusplus
}
#endif
#endif /* bufferedMQF_H */