Project
Loading...
Searching...
No Matches
HashTable.h
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef RANS_INTERNAL_CONTAINER_HASHTABLE_H_
17#define RANS_INTERNAL_CONTAINER_HASHTABLE_H_
18
19#include <cstdint>
20#include <string>
21#include <vector>
22#include <algorithm>
23#include <iterator>
24#include <cassert>
25
26#include <fairlogger/Logger.h>
27#include <absl/container/flat_hash_map.h>
28
30
31namespace o2::rans::internal
32{
33
34template <class source_T, class value_T>
36{
37 public:
39 using value_type = value_T;
40 using container_type = absl::flat_hash_map<source_type, value_type>;
41 using size_type = size_t;
42 using difference_type = std::ptrdiff_t;
46 using const_pointer = const value_type*;
47 using iterator = typename container_type::iterator;
48 using const_iterator = typename container_type::const_iterator;
49
50 HashTable() = default;
51 HashTable(value_type nullElement) : mNullElement{std::move(nullElement)} {};
52 HashTable(container_type container, value_type nullElement) : mContainer{std::move(container)}, mNullElement{std::move(nullElement)} {};
53
54 [[nodiscard]] inline const_reference getNullElement() const { return mNullElement; };
55
56 [[nodiscard]] inline const_reference operator[](source_type sourceSymbol) const
57 {
58 auto iter = mContainer.find(sourceSymbol);
59 if (iter != mContainer.end()) {
60 return iter->second;
61 } else {
62 return getNullElement();
63 }
64 };
65
66 [[nodiscard]] inline reference operator[](source_type sourceSymbol) { return mContainer[sourceSymbol]; };
67
68 [[nodiscard]] inline const_iterator find(source_type sourceSymbol) const { return mContainer.find(sourceSymbol); };
69
70 [[nodiscard]] inline size_type size() const noexcept { return mContainer.size(); };
71
72 [[nodiscard]] inline bool empty() const noexcept { return mContainer.empty(); };
73
74 [[nodiscard]] inline const_iterator cbegin() const noexcept { return mContainer.cbegin(); };
75
76 [[nodiscard]] inline const_iterator cend() const noexcept { return mContainer.cend(); };
77
78 [[nodiscard]] inline const_iterator begin() const noexcept { return cbegin(); };
79
80 [[nodiscard]] inline const_iterator end() const noexcept { return cend(); };
81
82 [[nodiscard]] inline iterator begin() noexcept { return mContainer.begin(); };
83
84 [[nodiscard]] inline iterator end() noexcept { return mContainer.end(); };
85
86 [[nodiscard]] inline container_type release() && noexcept { return std::move(this->mContainer); };
87
88 friend void swap(HashTable& a, HashTable& b) noexcept
89 {
90 using std::swap;
91 swap(a.mContainer, b.mContainer);
92 swap(a.mNullElement, b.mNullElement);
93 };
94
95 protected:
98};
99
100} // namespace o2::rans::internal
101
102#endif /* RANS_INTERNAL_CONTAINER_HASHTABLE_H_ */
common helper classes and functions
const_reference operator[](source_type sourceSymbol) const
Definition HashTable.h:56
friend void swap(HashTable &a, HashTable &b) noexcept
Definition HashTable.h:88
const_iterator cend() const noexcept
Definition HashTable.h:76
size_type size() const noexcept
Definition HashTable.h:70
container_type release() &&noexcept
Definition HashTable.h:86
const_iterator find(source_type sourceSymbol) const
Definition HashTable.h:68
const_iterator cbegin() const noexcept
Definition HashTable.h:74
const_iterator end() const noexcept
Definition HashTable.h:80
iterator end() noexcept
Definition HashTable.h:84
HashTable(container_type container, value_type nullElement)
Definition HashTable.h:52
const value_type * const_pointer
Definition HashTable.h:46
const value_type & const_reference
Definition HashTable.h:44
const_reference getNullElement() const
Definition HashTable.h:54
const_iterator begin() const noexcept
Definition HashTable.h:78
absl::flat_hash_map< source_type, value_type > container_type
Definition HashTable.h:40
typename container_type::iterator iterator
Definition HashTable.h:47
reference operator[](source_type sourceSymbol)
Definition HashTable.h:66
iterator begin() noexcept
Definition HashTable.h:82
HashTable(value_type nullElement)
Definition HashTable.h:51
typename container_type::const_iterator const_iterator
Definition HashTable.h:48
std::ptrdiff_t difference_type
Definition HashTable.h:42
bool empty() const noexcept
Definition HashTable.h:72
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
Defining DataPointCompositeObject explicitly as copiable.