AllianceDB  0.0.1
AllianceDB is an open-source suite, including benchmarks and libs for evaluating and improving stream operation algorithms on modern hardwares.
MultiThreadHashTable.h
Go to the documentation of this file.
1 
2 #ifndef _JOINALGO_NPJ_MULTITHREADHASHTABLE_H_
3 #define _JOINALGO_NPJ_MULTITHREADHASHTABLE_H_
4 #include "Types.h"
5 #include <stdint.h>
6 #include <memory>
7 #include <condition_variable>
8 #include <mutex>
9 namespace INTELLI {
10 
18 #define BUCKET_SIZE 4
19 class MtBucket;
20 typedef std::shared_ptr<MtBucket> MtBucketPtr;
21 //typedef vector<TuplePtr> MtTuplePtr;
22 typedef TuplePtr MtTuplePtr;
30 class MtBucket {
31  private:
32  std::mutex m_mut;
33  //vector<MtTuplePtr>tuples;
34  TuplePtr tuples[BUCKET_SIZE];
35  MtBucketPtr next = nullptr;
36  size_t count = 0;
37  public:
38  /*MtBucket(){
39  }
40  ~MtBucket(){}*/
44  void lock() {
45  while (!m_mut.try_lock());
46  }
50  void unlock() {
51  m_mut.unlock();
52  }
61  size_t probeTuple(TuplePtr tp);
66  /*MtBucketPtr getNext(){
67  return next;
68  }*/
69 };
76  private:
77 
78  public:
79  uint32_t hash_mask;
80  uint32_t skip_bits;
81  vector<MtBucket> buckets;
87  MultiThreadHashTable(size_t bks);
102  void buildTable(TuplePtr *tps, size_t len);
108  size_t probeTuple(TuplePtr tp);
109 
110 };
111 typedef std::shared_ptr<MultiThreadHashTable> MultiThreadHashTablePtr;
115 }
116 #endif //ALIANCEDB_INCLUDE_JOINALGO_NPJ_MULTITHREADHASHTABLE_H_
The multithread-supported bucket.
Definition: MultiThreadHashTable.h:30
size_t probeTuple(TuplePtr tp)
probe one tuple, just on the bucket
void duplicatedInsert(TuplePtr tp)
Insert a tuple, allowing key duplication.
void lock()
lock this bucket
Definition: MultiThreadHashTable.h:44
void unlock()
unlock this bucket
Definition: MultiThreadHashTable.h:50
The multithread-supported hash table, holding buckets.
Definition: MultiThreadHashTable.h:75
size_t probeTuple(TuplePtr tp)
probe one tuple
void buildTable(TuplePtrQueue tps)
build the hashtable from tuple queue
void buildTable(TuplePtr *tps, size_t len)
build the hashtable from tuple memory aray
MultiThreadHashTable(size_t bks)
pre-init with several buckets
std::shared_ptr< class Tuple > TuplePtr
The class to describe a shared pointer to Tuple.
Definition: Types.h:150
std::shared_ptr< INTELLI::SPSCQueue< INTELLI::TuplePtr > > TuplePtrQueue
To describe a queue of TuplePtr under SPSCQueue.
Definition: Types.h:228
Definition: DatasetTool.h:10