5G-LENA nr-v3.0-32-g83aee33
The 5G/NR module for the ns-3 simulator
Loading...
Searching...
No Matches
beam-id.cc
1/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
2
3// Copyright (c) 2020 Centre Tecnologic de Telecomunicacions de Catalunya (CTTC)
4//
5// SPDX-License-Identifier: GPL-2.0-only
6
7#include "beam-id.h"
8
9namespace ns3
10{
11const BeamId OMNI_BEAM_ID = BeamId(UINT16_MAX, UINT16_MAX);
12const BeamId PREDEFINED_BEAM_ID = BeamId(UINT16_MAX - 1, UINT16_MAX - 1);
13
14std::ostream&
15operator<<(std::ostream& os, const BeamId& item)
16{
17 os << "[Sector: " << static_cast<uint16_t>(item.GetSector())
18 << " elevation: " << item.GetElevation() << "]";
19 return os;
20}
21
25
26BeamId::BeamId(uint16_t sector, double elevation)
27{
28 m_sector = sector;
29 m_elevation = elevation;
30}
31
32bool
34{
35 return m_sector == p.GetSector() && m_elevation == p.GetElevation();
36}
37
38bool
40{
41 return (m_sector != p.GetSector() || m_elevation != p.GetElevation());
42}
43
44uint16_t
46{
47 return m_sector;
48}
49
50double
52{
53 return m_elevation;
54}
55
57BeamId::GetEmptyBeamId()
58{
59 return BeamId(0, 0);
60}
61
68static constexpr uint32_t
69Cantor(uint16_t x1, uint16_t x2)
70{
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:28
uint16_t GetSector() const
Extract the sector from the beam id.
Definition beam-id.cc:45
uint32_t GetCantor() const
Definition beam-id.cc:75
double GetElevation() const
Extract the elevation from the beam id.
Definition beam-id.cc:51
BeamId()
Default constructor which created beamId with 0 sector and 0 elevation.
Definition beam-id.cc:22
bool operator!=(const BeamId &p) const
Overrides != operator for the general use case.
Definition beam-id.cc:39
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:33
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:12
const BeamId OMNI_BEAM_ID
Name of the OMNI beam.
Definition beam-id.cc:11
size_t operator()(const BeamId &x) const
operator ()
Definition beam-id.cc:81