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//! Base class for hashmap element.
25//! @remarks
26//! Object should inherit this class to be able to be a member of Hashmap.
27class HashmapNode : public NonCopyable<HashmapNode> {
28public:
29 //! Hashmap node data.
31 //! Previous node in bucket.
33
34 //! Next node in bucket.
36
37 //! Cached node hash.
39
40 //! The bucket this node belongs to.
41 //! @remarks
42 //! NULL if node is not member of any hashmap.
43 void* bucket;
44
46 : prev(NULL)
47 , next(NULL)
48 , hash(0)
49 , bucket(NULL) {
50 }
51
52 //! Get HashmapNode object that contains this HashmapData object.
54 return ROC_CONTAINER_OF(this, HashmapNode, hashmap_data_);
55 }
56 };
57
58 ~HashmapNode() {
59 if (hashmap_data_.bucket != NULL) {
60 roc_panic("hashmap node:"
61 " can't call destructor for an element that is still in hashmap");
62 }
63 }
64
65 //! Get hashmap node data.
67 return &hashmap_data_;
68 }
69
70private:
71 mutable HashmapNodeData hashmap_data_;
72};
73
74} // namespace core
75} // namespace roc
76
77#endif // ROC_CORE_HASHMAP_NODE_H_
Base class for hashmap element.
HashmapNodeData * hashmap_node_data() const
Get hashmap node data.
Base class for non-copyable objects.
Definition noncopyable.h:23
Hash sum.
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
size_t hashsum_t
Hash type.
Definition hashsum.h:21
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.
HashmapNode * container_of()
Get HashmapNode object that contains this HashmapData object.
void * bucket
The bucket this node belongs to.
hashsum_t hash
Cached node hash.
HashmapNodeData * next
Next node in bucket.
HashmapNodeData * prev
Previous node in bucket.