Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
LinearOffsetMap.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* HashTable.cc (C) 2000-2024 */
9/* */
10/* Hash table. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/LinearOffsetMap.h"
15
16#include <iostream>
17
18/*---------------------------------------------------------------------------*/
19/*---------------------------------------------------------------------------*/
20
21namespace Arcane
22{
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27template <typename DataType> void LinearOffsetMap<DataType>::
28add(DataType size, DataType offset)
29{
30 std::cout << "ADD size=" << size << " offset=" << offset << "\n";
31 m_offset_map.insert(std::make_pair(size, offset));
32}
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
37template <typename DataType> DataType LinearOffsetMap<DataType>::
39{
40 auto x = m_offset_map.lower_bound(size);
41 std::cout << "TRY_FIND size=" << size << " n=" << m_offset_map.size() << "\n";
42 if (x == m_offset_map.end())
43 return (-1);
44 DataType offset = x->second;
45 DataType offset_size = x->first;
46 std::cout << "FOUND size=" << size << " found_offset=" << offset
47 << " offset_size=" << offset_size << "\n";
48 m_offset_map.erase(x);
49 DataType remaining_size = offset_size - size;
50 if (remaining_size != 0)
51 add(remaining_size, offset + size);
52 return offset;
53}
54
55/*---------------------------------------------------------------------------*/
56/*---------------------------------------------------------------------------*/
57
58template <typename DataType> Int32 LinearOffsetMap<DataType>::
59size() const
60{
61 return static_cast<Int32>(m_offset_map.size());
62}
63
64/*---------------------------------------------------------------------------*/
65/*---------------------------------------------------------------------------*/
66
67template class LinearOffsetMap<Int32>;
68template class LinearOffsetMap<Int64>;
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
72
73} // namespace Arcane
74
75/*---------------------------------------------------------------------------*/
76/*---------------------------------------------------------------------------*/
List of linear offsets.
void add(DataType size, DataType offset)
Adds an offset offset of size size.
Int32 size() const
Number of elements in the table.
DataType getAndRemoveOffset(DataType size)
Retrieves a sufficient offset for an element of size size.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.