Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
LinearOffsetMap.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 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/* Table de hachage. */
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>::
38getAndRemoveOffset(DataType size)
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/*---------------------------------------------------------------------------*/
void add(DataType size, DataType offset)
Ajoute un offset offset de taille size.
Int32 size() const
Nombre d'éléments dans la table.
DataType getAndRemoveOffset(DataType size)
Récupère un offset suffisant pour un élément de taille size.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-