5G-LENA nr-v3.1-69-g2dd513a7
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
beam-id.cc
1// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
2//
3// SPDX-License-Identifier: GPL-2.0-only
4
5#include "beam-id.h"
6
7namespace ns3
8{
9const BeamId OMNI_BEAM_ID = BeamId(UINT16_MAX, UINT16_MAX);
10const BeamId PREDEFINED_BEAM_ID = BeamId(UINT16_MAX - 1, UINT16_MAX - 1);
11
12std::ostream&
13operator<<(std::ostream& os, const BeamId& item)
14{
15 os << "[Sector: " << static_cast<uint16_t>(item.GetSector())
16 << " elevation: " << item.GetElevation() << "]";
17 return os;
18}
19
23
24BeamId::BeamId(uint16_t sector, double elevation)
25{
26 m_sector = sector;
27 m_elevation = elevation;
28}
29
30bool
32{
33 return m_sector == p.GetSector() && m_elevation == p.GetElevation();
34}
35
36bool
38{
39 return (m_sector != p.GetSector() || m_elevation != p.GetElevation());
40}
41
42uint16_t
44{
45 return m_sector;
46}
47
48double
50{
51 return m_elevation;
52}
53
55BeamId::GetEmptyBeamId()
56{
57 return BeamId(0, 0);
58}
59
66static constexpr uint32_t
67Cantor(uint16_t x1_16, uint16_t x2_16)
68{
69 uint32_t x1 = x1_16;
70 uint32_t x2 = x2_16;
71 return (((x1 + x2) * (x1 + x2 + 1)) / 2) + x2;
72}
73
74uint32_t
76{
77 return Cantor(m_sector, static_cast<uint16_t>(m_elevation));
78}
79
80size_t
82{
83 return std::hash<uint32_t>()(x.GetCantor());
84}
85
86} /* namespace ns3 */
Representation of a beam id.
Definition beam-id.h:26
uint16_t GetSector() const
Extract the sector from the beam id.
Definition beam-id.cc:43
uint32_t GetCantor() const
Definition beam-id.cc:75
double GetElevation() const
Extract the elevation from the beam id.
Definition beam-id.cc:49
BeamId()
Default constructor which created beamId with 0 sector and 0 elevation.
Definition beam-id.cc:20
bool operator!=(const BeamId &p) const
Overrides != operator for the general use case.
Definition beam-id.cc:37
bool operator==(const BeamId &p) const
Objects of this class are used as key in hash table. This class must implement operator ==() to handl...
Definition beam-id.cc:31
const BeamId PREDEFINED_BEAM_ID
Reserved ID for the predefined directional beam if it cannot be expressed through sector and elevatio...
Definition beam-id.cc:10
const BeamId OMNI_BEAM_ID
Name of the OMNI beam.
Definition beam-id.cc:9
size_t operator()(const BeamId &x) const
operator ()
Definition beam-id.cc:81