5G-LENA nr-v3.3-159-ga6832aa7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
nr-mac-harq-vector.h
1// Copyright (c) 2019 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#pragma once
6
7#include "nr-mac-harq-process.h"
8
9#include <unordered_map>
10
11namespace ns3
12{
13
29class NrMacHarqVector : private std::unordered_map<uint8_t, HarqProcess>
30{
31 public:
32 friend std::ostream& operator<<(std::ostream& os, const NrMacHarqVector& item);
36 typedef typename std::unordered_map<uint8_t, HarqProcess>::iterator iterator;
40 typedef typename std::unordered_map<uint8_t, HarqProcess>::const_iterator const_iterator;
41
45 NrMacHarqVector() = default;
46
53 void SetMaxSize(uint8_t size)
54 {
55 m_maxSize = size;
56 reserve(size);
57 for (auto i = 0; i < size; ++i)
58 {
59 emplace(i, HarqProcess());
60 }
61 }
62
68 bool Erase(uint8_t id);
69
76 bool Insert(uint8_t* id, const HarqProcess& element);
77
83 const iterator Find(uint8_t key)
84 {
85 return this->find(key);
86 }
87
93 {
94 return this->begin();
95 }
96
101 const iterator End()
102 {
103 return this->end();
104 }
105
111 {
112 return this->cbegin();
113 }
114
120 {
121 return this->cend();
122 }
123
130 bool Exist(uint8_t id) const
131 {
132 // could be id > max_size?
133 return find(id) != end();
134 }
135
141 HarqProcess& Get(uint8_t id)
142 {
143 NS_ASSERT(Exist(id));
144 return find(id)->second;
145 }
146
152 const HarqProcess& Get(uint8_t id) const
153 {
154 NS_ASSERT(Exist(id));
155 return find(id)->second;
156 }
157
162 uint8_t FirstAvailableId() const
163 {
164 for (const auto& it : *this)
165 {
166 if (!it.second.m_active)
167 {
168 return it.first;
169 }
170 }
171 return 255;
172 }
173
178 bool CanInsert() const
179 {
180 return Size() < m_maxSize;
181 }
182
187 uint32_t Size() const
188 {
189 return m_usedSize;
190 }
191
192 private:
193 uint8_t m_maxSize{0};
194 uint8_t m_usedSize{0};
195};
196
203std::ostream& operator<<(std::ostream& os, const HarqProcess& item);
204
205} // namespace ns3
Data structure to save all the HARQ process of an UE.
const iterator Begin()
Begin of the vector.
const HarqProcess & Get(uint8_t id) const
Get a const reference to a process.
bool Insert(uint8_t *id, const HarqProcess &element)
Insert a process.
uint32_t Size() const
Get the used size of the vector.
const_iterator CEnd()
Const end of the vector.
uint8_t FirstAvailableId() const
Find the first (INACTIVE) ID.
std::unordered_map< uint8_t, HarqProcess >::const_iterator const_iterator
const_iterator of the map
NrMacHarqVector()=default
Default constructor.
const iterator End()
End of the vector.
std::unordered_map< uint8_t, HarqProcess >::iterator iterator
iterator of the map
bool CanInsert() const
Can an ID be inserted?
const_iterator CBegin()
Const begin of the vector.
bool Exist(uint8_t id) const
Check if the ID exists in the map.
const iterator Find(uint8_t key)
Find a process.
bool Erase(uint8_t id)
Erase the selected process.
void SetMaxSize(uint8_t size)
Set and reserve the size of the vector.
HarqProcess & Get(uint8_t id)
Get a reference to a process.
The HarqProcess struct.