Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
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
"
16
#include "
roc_core/macro_helpers.h
"
17
#include "
roc_core/noncopyable.h
"
18
#include "
roc_core/panic.h
"
19
#include "
roc_core/stddefs.h
"
20
21
namespace
roc
{
22
namespace
core
{
23
24
//! Hashmap node internal data.
25
struct
HashmapData {
26
//! Previous node in bucket.
27
HashmapData*
bucket_prev
;
28
29
//! Next node in bucket.
30
HashmapData*
bucket_next
;
31
32
//! Previous node in list of all nodes.
33
HashmapData*
all_prev
;
34
35
//! Next node in in list of all nodes.
36
HashmapData*
all_next
;
37
38
//! Cached node hash.
39
hashsum_t
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
46
HashmapData()
47
:
bucket_prev
(NULL)
48
,
bucket_next
(NULL)
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.
61
template
<
class
Tag =
void
>
class
HashmapNode
:
public
NonCopyable<HashmapNode<Tag> > {
62
public
:
63
~HashmapNode
() {
64
if
(hashmap_data_.bucket != NULL) {
65
roc_panic
(
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.
71
static
HashmapNode
*
hashmap_node
(
HashmapData
* data) {
72
return
ROC_CONTAINER_OF
(data,
HashmapNode
, hashmap_data_);
73
}
74
75
//! Get pointer to internal data.
76
HashmapData
*
hashmap_data
()
const
{
77
return
&hashmap_data_;
78
}
79
80
private
:
81
mutable
HashmapData
hashmap_data_;
82
};
83
84
}
// namespace core
85
}
// namespace roc
86
87
#endif
// ROC_CORE_HASHMAP_NODE_H_
roc::core::HashmapNode
Base class for Hashmap element.
Definition
hashmap_node.h:61
roc::core::HashmapNode::hashmap_node
static HashmapNode * hashmap_node(HashmapData *data)
Get pointer to parent node from pointer to internal data.
Definition
hashmap_node.h:71
roc::core::HashmapNode::hashmap_data
HashmapData * hashmap_data() const
Get pointer to internal data.
Definition
hashmap_node.h:76
hashsum.h
Hash sum.
macro_helpers.h
Helper macros.
ROC_CONTAINER_OF
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition
macro_helpers.h:37
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::hashsum_t
size_t hashsum_t
Hash type.
Definition
hashsum.h:21
roc
Root namespace.
noncopyable.h
Non-copyable object.
panic.h
Panic.
roc_panic
#define roc_panic(...)
Print error message and terminate program gracefully.
Definition
panic.h:50
stddefs.h
Commonly used types and functions.
roc::core::HashmapData
Hashmap node internal data.
Definition
hashmap_node.h:25
roc::core::HashmapData::bucket_next
HashmapData * bucket_next
Next node in bucket.
Definition
hashmap_node.h:30
roc::core::HashmapData::all_prev
HashmapData * all_prev
Previous node in list of all nodes.
Definition
hashmap_node.h:33
roc::core::HashmapData::all_next
HashmapData * all_next
Next node in in list of all nodes.
Definition
hashmap_node.h:36
roc::core::HashmapData::bucket
void * bucket
The bucket this node belongs to.
Definition
hashmap_node.h:44
roc::core::HashmapData::hash
hashsum_t hash
Cached node hash.
Definition
hashmap_node.h:39
roc::core::HashmapData::bucket_prev
HashmapData * bucket_prev
Previous node in bucket.
Definition
hashmap_node.h:27
roc_core
hashmap_node.h
Generated by
1.17.0