code documantation work in progress
This commit is contained in:
parent
4b957f8dd3
commit
1ae474d15c
@ -7,8 +7,11 @@ namespace bolt
|
||||
|
||||
namespace config
|
||||
{
|
||||
static constexpr size_t N = 65535; /* chunk size */
|
||||
static constexpr size_t C = N + 2; /* end mark */
|
||||
/** chunk size */
|
||||
static constexpr size_t N = 65535;
|
||||
|
||||
/** end mark */
|
||||
static constexpr size_t C = N + 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,17 +5,38 @@ namespace bolt
|
||||
|
||||
enum class PackType
|
||||
{
|
||||
Null, // denotes absence of a value
|
||||
Boolean, // denotes a type with two possible values (t/f)
|
||||
Integer, // 64-bit signed integral number
|
||||
Float, // 64-bit floating point number
|
||||
Bytes, // binary data
|
||||
String, // unicode string
|
||||
List, // collection of values
|
||||
Map, // collection of zero or more key/value pairs
|
||||
Struct, // zero or more packstream values
|
||||
EndOfStream, // denotes stream value end
|
||||
Reserved // reserved for future use
|
||||
/** denotes absence of a value */
|
||||
Null,
|
||||
|
||||
/** denotes a type with two possible values (t/f) */
|
||||
Boolean,
|
||||
|
||||
/** 64-bit signed integral number */
|
||||
Integer,
|
||||
|
||||
/** 64-bit floating point number */
|
||||
Float,
|
||||
|
||||
/** binary data */
|
||||
Bytes,
|
||||
|
||||
/** unicode string */
|
||||
String,
|
||||
|
||||
/** collection of values */
|
||||
List,
|
||||
|
||||
/** collection of zero or more key/value pairs */
|
||||
Map,
|
||||
|
||||
/** zero or more packstream values */
|
||||
Struct,
|
||||
|
||||
/** denotes stream value end */
|
||||
EndOfStream,
|
||||
|
||||
/** reserved for future use */
|
||||
Reserved
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ class BoltSerializer
|
||||
public:
|
||||
BoltSerializer(Stream &stream) : encoder(stream) {}
|
||||
|
||||
/* Serializes the vertex accessor into the packstream format
|
||||
/** Serializes the vertex accessor into the packstream format
|
||||
*
|
||||
* struct[size = 3] Vertex [signature = 0x4E] {
|
||||
* Integer node_id;
|
||||
@ -64,7 +64,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/* Serializes the vertex accessor into the packstream format
|
||||
/** Serializes the vertex accessor into the packstream format
|
||||
*
|
||||
* struct[size = 5] Edge [signature = 0x52] {
|
||||
* Integer edge_id;
|
||||
@ -79,7 +79,7 @@ public:
|
||||
|
||||
void write_null() { encoder.write_null(); }
|
||||
|
||||
void write(const Null &v) { encoder.write_null(); }
|
||||
void write(const Null &) { encoder.write_null(); }
|
||||
|
||||
void write(const Bool &prop) { encoder.write_bool(prop.value()); }
|
||||
|
||||
|
@ -10,9 +10,10 @@
|
||||
namespace bolt
|
||||
{
|
||||
|
||||
// compiled queries have to use this class in order to return results
|
||||
// query code should not know about bolt protocol
|
||||
|
||||
/**
|
||||
* compiled queries have to use this class in order to return results
|
||||
* query code should not know about bolt protocol
|
||||
*/
|
||||
template <class Socket>
|
||||
class RecordStream
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
/* Memgraph Communication protocol
|
||||
/* Memgraph communication protocol
|
||||
* gate is the first name proposal for the protocol */
|
||||
|
||||
// TODO
|
||||
|
@ -1,3 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
/* HTTP & HTTPS implementation */
|
||||
/* TODO: HTTP & HTTPS implementations */
|
||||
|
@ -1,67 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
/*
|
||||
Implementation of a generic Bloom Filter.
|
||||
|
||||
Read more about bloom filters here:
|
||||
http://en.wikipedia.org/wiki/Bloom_filter
|
||||
http://www.jasondavies.com/bloomfilter/
|
||||
*/
|
||||
|
||||
// Type specifies the type of data stored
|
||||
/**
|
||||
* Implementation of a generic Bloom Filter.
|
||||
* Read more about bloom filters here:
|
||||
* http://en.wikipedia.org/wiki/Bloom_filter
|
||||
* http://www.jasondavies.com/bloomfilter/
|
||||
*
|
||||
* Type specifies the type of data stored
|
||||
*/
|
||||
template <class Type, int BucketSize = 8>
|
||||
class BloomFilter {
|
||||
private:
|
||||
using HashFunction = std::function<uint64_t(const Type&)>;
|
||||
using CompresionFunction = std::function<int(uint64_t)>;
|
||||
class BloomFilter
|
||||
{
|
||||
private:
|
||||
using HashFunction = std::function<uint64_t(const Type &)>;
|
||||
using CompresionFunction = std::function<int(uint64_t)>;
|
||||
|
||||
std::bitset<BucketSize> filter_;
|
||||
std::vector<HashFunction> hashes_;
|
||||
CompresionFunction compression_;
|
||||
std::vector<int> buckets;
|
||||
std::bitset<BucketSize> filter_;
|
||||
std::vector<HashFunction> hashes_;
|
||||
CompresionFunction compression_;
|
||||
std::vector<int> buckets;
|
||||
|
||||
int default_compression(uint64_t hash) { return hash % BucketSize; }
|
||||
int default_compression(uint64_t hash) { return hash % BucketSize; }
|
||||
|
||||
void get_buckets(const Type& data) {
|
||||
for (int i = 0; i < hashes_.size(); i++)
|
||||
buckets[i] = compression_(hashes_[i](data));
|
||||
}
|
||||
|
||||
void print_buckets(std::vector<uint64_t>& buckets) {
|
||||
for (int i = 0; i < buckets.size(); i++) {
|
||||
std::cout << buckets[i] << " ";
|
||||
void get_buckets(const Type &data)
|
||||
{
|
||||
for (int i = 0; i < hashes_.size(); i++)
|
||||
buckets[i] = compression_(hashes_[i](data));
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
public:
|
||||
BloomFilter(std::vector<HashFunction> funcs,
|
||||
CompresionFunction compression = {})
|
||||
: hashes_(funcs) {
|
||||
if (!compression)
|
||||
compression_ = std::bind(&BloomFilter::default_compression, this,
|
||||
std::placeholders::_1);
|
||||
else
|
||||
compression_ = compression;
|
||||
void print_buckets(std::vector<uint64_t> &buckets)
|
||||
{
|
||||
for (int i = 0; i < buckets.size(); i++)
|
||||
{
|
||||
std::cout << buckets[i] << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
buckets.resize(hashes_.size());
|
||||
}
|
||||
public:
|
||||
BloomFilter(std::vector<HashFunction> funcs,
|
||||
CompresionFunction compression = {})
|
||||
: hashes_(funcs)
|
||||
{
|
||||
if (!compression)
|
||||
compression_ = std::bind(&BloomFilter::default_compression, this,
|
||||
std::placeholders::_1);
|
||||
else
|
||||
compression_ = compression;
|
||||
|
||||
bool contains(const Type& data) {
|
||||
get_buckets(data);
|
||||
bool contains_element = true;
|
||||
buckets.resize(hashes_.size());
|
||||
}
|
||||
|
||||
for (int i = 0; i < buckets.size(); i++)
|
||||
contains_element &= filter_[buckets[i]];
|
||||
bool contains(const Type &data)
|
||||
{
|
||||
get_buckets(data);
|
||||
bool contains_element = true;
|
||||
|
||||
return contains_element;
|
||||
}
|
||||
for (int i = 0; i < buckets.size(); i++)
|
||||
contains_element &= filter_[buckets[i]];
|
||||
|
||||
void insert(const Type& data) {
|
||||
get_buckets(data);
|
||||
return contains_element;
|
||||
}
|
||||
|
||||
for (int i = 0; i < buckets.size(); i++) filter_[buckets[i]] = true;
|
||||
}
|
||||
void insert(const Type &data)
|
||||
{
|
||||
get_buckets(data);
|
||||
|
||||
for (int i = 0; i < buckets.size(); i++)
|
||||
filter_[buckets[i]] = true;
|
||||
}
|
||||
};
|
||||
|
@ -5,9 +5,12 @@
|
||||
|
||||
using std::pair;
|
||||
|
||||
// Multi thread safe map based on skiplist.
|
||||
// K - type of key.
|
||||
// T - type of data.
|
||||
/**
|
||||
* Multi thread safe map based on skiplist.
|
||||
*
|
||||
* @tparam K is a type of key.
|
||||
* @tparam T is a type of data.
|
||||
*/
|
||||
template <typename K, typename T>
|
||||
class ConcurrentMap
|
||||
{
|
||||
|
@ -5,9 +5,12 @@
|
||||
|
||||
using std::pair;
|
||||
|
||||
// Multi thread safe multi map based on skiplist.
|
||||
// K - type of key.
|
||||
// T - type of data.
|
||||
/**
|
||||
* Multi thread safe multi map based on skiplist.
|
||||
*
|
||||
* @tparam K is a type of key.
|
||||
* @tparam T is a type of data.
|
||||
*/
|
||||
template <typename K, typename T>
|
||||
class ConcurrentMultiMap
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include "data_structures/concurrent/skiplist_gc.hpp"
|
||||
|
||||
/* @brief Concurrent lock-based skiplist with fine grained locking
|
||||
/** @brief Concurrent lock-based skiplist with fine grained locking
|
||||
*
|
||||
* From Wikipedia:
|
||||
* "A skip list is a data structure that allows fast search within an
|
||||
@ -97,11 +97,13 @@ template <class T, size_t H = 32, class lock_t = SpinLock>
|
||||
class SkipList : private Lockable<lock_t>
|
||||
{
|
||||
public:
|
||||
// computes the height for the new node from the interval [1...H]
|
||||
// with p(k) = (1/2)^k for all k from the interval
|
||||
/**
|
||||
* computes the height for the new node from the interval [1...H]
|
||||
* with p(k) = (1/2)^k for all k from the interval
|
||||
*/
|
||||
static thread_local FastBinomial<H> rnd;
|
||||
|
||||
/* @brief Wrapper class for flags used in the implementation
|
||||
/** @brief Wrapper class for flags used in the implementation
|
||||
*
|
||||
* MARKED flag is used to logically delete a node.
|
||||
* FULLY_LINKED is used to mark the node as fully inserted, i.e. linked
|
||||
@ -224,12 +226,14 @@ public:
|
||||
|
||||
Placeholder<T> data;
|
||||
|
||||
// this creates an array of the size zero. we can't put any sensible
|
||||
// value here since we don't know what size it will be untill the
|
||||
// node is allocated. we could make it a Node** but then we would
|
||||
// have two memory allocations, one for node and one for the forward
|
||||
// list. this way we avoid expensive malloc/free calls and also cache
|
||||
// thrashing when following a pointer on the heap
|
||||
/**
|
||||
* this creates an array of the size zero. we can't put any sensible
|
||||
* value here since we don't know what size it will be untill the
|
||||
* node is allocated. we could make it a Node** but then we would
|
||||
* have two memory allocations, one for node and one for the forward
|
||||
* list. this way we avoid expensive malloc/free calls and also cache
|
||||
* thrashing when following a pointer on the heap
|
||||
*/
|
||||
std::atomic<Node *> tower[0];
|
||||
};
|
||||
|
||||
@ -441,6 +445,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
// TODO: figure why start is unused
|
||||
static int update_path(SkipList *skiplist, int start, const K &item,
|
||||
Node *preds[], Node *succs[])
|
||||
{
|
||||
@ -664,14 +669,18 @@ private:
|
||||
return (node == nullptr) || item < node->value();
|
||||
}
|
||||
|
||||
// Returns first occurence of item if there exists one.
|
||||
/**
|
||||
* Returns first occurence of item if there exists one.
|
||||
*/
|
||||
template <class K>
|
||||
ConstIterator find(const K &item) const
|
||||
{
|
||||
return const_cast<SkipList *>(this)->find_node<ConstIterator, K>(item);
|
||||
}
|
||||
|
||||
// Returns first occurence of item if there exists one.
|
||||
/**
|
||||
* Returns first occurence of item if there exists one.
|
||||
*/
|
||||
template <class K>
|
||||
Iterator find(const K &item)
|
||||
{
|
||||
@ -689,7 +698,9 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Returns iterator on searched element or the first larger element.
|
||||
/**
|
||||
* Returns iterator on searched element or the first larger element.
|
||||
*/
|
||||
template <class It, class K>
|
||||
It find_or_larger(const K &item)
|
||||
{
|
||||
@ -758,8 +769,11 @@ private:
|
||||
return valid;
|
||||
}
|
||||
|
||||
// Inserts non unique data into list.
|
||||
// NOTE: Uses modified logic from insert method.
|
||||
/**
|
||||
* Inserts non unique data into list.
|
||||
*
|
||||
* NOTE: Uses modified logic from insert method.
|
||||
*/
|
||||
Iterator insert_non_unique(T &&data, Node *preds[], Node *succs[])
|
||||
{
|
||||
while (true) {
|
||||
@ -823,9 +837,12 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Insert unique data
|
||||
// F - type of funct which will create new node if needed. Recieves height
|
||||
// of node.
|
||||
/**
|
||||
* Insert unique data
|
||||
*
|
||||
* F - type of funct which will create new node if needed. Recieves height
|
||||
* of node.
|
||||
*/
|
||||
std::pair<Iterator, bool> insert(Node *preds[], Node *succs[], T &&data)
|
||||
{
|
||||
while (true) {
|
||||
@ -857,8 +874,11 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Insert unique data
|
||||
// NOTE: This is almost all duplicate code from insert.
|
||||
/**
|
||||
* Insert unique data
|
||||
*
|
||||
* NOTE: This is almost all duplicate code from insert.
|
||||
*/
|
||||
template <class K, class... Args>
|
||||
std::pair<Iterator, bool> emplace(Node *preds[], Node *succs[], K &key,
|
||||
Args &&... args)
|
||||
@ -893,9 +913,11 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Inserts data to specified locked location.
|
||||
/**
|
||||
* Inserts data to specified locked location.
|
||||
*/
|
||||
Iterator insert_here(Node *new_node, Node *preds[], Node *succs[],
|
||||
int height, guard_t guards[])
|
||||
int height, guard_t guards[]) // TODO: querds unused
|
||||
{
|
||||
// Node::create(std::move(data), height)
|
||||
// link the predecessors and successors, e.g.
|
||||
@ -921,10 +943,12 @@ private:
|
||||
!node->flags.is_marked();
|
||||
}
|
||||
|
||||
// Remove item found with fp with arguments skiplist,preds and succs.
|
||||
// fp has to fill preds and succs which reflect location of item or return
|
||||
// -1 as in not found otherwise returns level on which the item was first
|
||||
// found.
|
||||
/**
|
||||
* Removes item found with fp with arguments skiplist, preds and succs.
|
||||
* fp has to fill preds and succs which reflect location of item or return
|
||||
* -1 as in not found otherwise returns level on which the item was first
|
||||
* found.
|
||||
*/
|
||||
template <class K>
|
||||
bool remove(const K &item, Node *preds[], Node *succs[],
|
||||
int (*fp)(SkipList *, int, const K &, Node *[], Node *[]))
|
||||
@ -966,7 +990,9 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// number of elements
|
||||
/**
|
||||
* number of elements
|
||||
*/
|
||||
std::atomic<size_t> count{0};
|
||||
Node *header;
|
||||
SkiplistGC<Node> gc;
|
||||
|
@ -1 +0,0 @@
|
||||
// TODO
|
@ -1 +0,0 @@
|
||||
// TODO
|
Loading…
Reference in New Issue
Block a user