Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
hashmap_node.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/hashmap_node.h
10//! @brief Hashmap node.
11
12#ifndef ROC_CORE_HASHMAP_NODE_H_
13#define ROC_CORE_HASHMAP_NODE_H_
14
15#include "roc_core/hashsum.h"
18#include "roc_core/panic.h"
19#include "roc_core/stddefs.h"
20
21namespace roc {
22namespace core {
23
24//! Hashmap node internal data.
26 //! Previous node in bucket.
28
29 //! Next node in bucket.
31
32 //! Previous node in list of all nodes.
34
35 //! Next node in in list of all nodes.
37
38 //! Cached node hash.
40
41 //! The bucket this node belongs to.
42 //! @remarks
43 //! NULL if node is not member of any hashmap.
44 void* bucket;
45
49 , all_prev(NULL)
50 , all_next(NULL)
51 , hash(0)
52 , bucket(NULL) {
53 }
54};
55
56//! Base class for Hashmap element.
57//! @remarks
58//! Object should inherit this class to be able to be a member of Hashmap.
59//! Tag allows to inherit multiple copies of ListNode and include same
60//! object into multiple lists.
61template <class Tag = void> class HashmapNode : public NonCopyable<HashmapNode<Tag> > {
62public:
63 ~HashmapNode() {
64 if (hashmap_data_.bucket != NULL) {
66 "hashmap node: attempt to destroy node while it's still in hashmap");
67 }
68 }
69
70 //! Get pointer to parent node from pointer to internal data.
72 return ROC_CONTAINER_OF(data, HashmapNode, hashmap_data_);
73 }
74
75 //! Get pointer to internal data.
77 return &hashmap_data_;
78 }
79
80private:
81 mutable HashmapData hashmap_data_;
82};
83
84} // namespace core
85} // namespace roc
86
87#endif // ROC_CORE_HASHMAP_NODE_H_
Base class for Hashmap element.
static HashmapNode * hashmap_node(HashmapData *data)
Get pointer to parent node from pointer to internal data.
HashmapData * hashmap_data() const
Get pointer to internal data.
Base class for non-copyable objects.
Definition noncopyable.h:23
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Hash sum.
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Root namespace.
Non-copyable object.
Panic.
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition panic.h:50
Commonly used types and functions.
Hashmap node internal data.
HashmapData * bucket_next
Next node in bucket.
HashmapData * all_prev
Previous node in list of all nodes.
HashmapData * all_next
Next node in in list of all nodes.
void * bucket
The bucket this node belongs to.
hashsum_t hash
Cached node hash.
HashmapData * bucket_prev
Previous node in bucket.