TrioCFD 1.9.9_beta
TrioCFD documentation
Loading...
Searching...
No Matches
Static_Int_Lists.h
1/****************************************************************************
2* Copyright (c) 2024, CEA
3* All rights reserved.
4*
5* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8* 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9*
10* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
11* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
12* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
13*
14*****************************************************************************/
15#ifndef Static_Int_Lists_included
16#define Static_Int_Lists_included
17
18#include <TRUSTTabs_forward.h>
19#include <TRUSTArray.h>
20
21/*! @brief This class allows storing lists of integers accessible in constant time.
22 *
23 * The size of the lists cannot change without
24 * losing the content (these are static lists).
25 * Example:
26 * Static_Int_List l;
27 * ArrOfInt tailles(3);
28 * tailles[0] = 2; tailles[1] = 3; tailles[2] = 0;
29 * // Reserve memory for three lists of size 2, 3 and 0:
30 * l.set_list_sizes(tailles);
31 * // Assign a value to the second element of the first list:
32 * l.set_value(0,1,765);
33 * // Print the value
34 * Cout << l(0,1);
35 *
36 */
37template <typename _SIZE_>
39{
40public:
41 using int_t = _SIZE_;
42 using ArrOfInt_t = ArrOfInt_T<_SIZE_>;
43 using ArrsOfInt_t = ArrsOfInt_T<_SIZE_>;
44
45 void set_list_sizes(const ArrOfInt_t& sizes);
46 void reset();
47
48 void copy_list_to_array(int_t i_liste, ArrOfInt_t& array) const;
49
50 inline void set_value(int_t i_liste, int_t i_element, int_t valeur);
51 inline int_t operator() (int_t i_liste, int_t i_element) const;
52 inline int_t get_list_size(int_t i_liste) const;
53 inline int_t get_nb_lists() const;
54 const ArrOfInt_t& get_index() const { return index_; }
55 const ArrOfInt_t& get_data() const { return valeurs_; }
56 void set_data(const ArrOfInt_t& data);
57 void set_index_data(const ArrOfInt_t& index, const ArrOfInt_t& data);
59 void set(const ArrsOfInt_t& src);
60
61 Sortie& printOn(Sortie& os) const;
63 Sortie& ecrire(Sortie& os) const;
64
65private:
66 // Integer lists are stored contiguously
67 // in the valeurs_ array.
68 // The first element of list i is valeurs_[index_[i]]
69 // and the last element is valeurs_[index_[i+1]-1]
70 // (similar to Morse storage of matrices).
71 ArrOfInt_t index_;
72 ArrOfInt_t valeurs_;
73};
74
75/*! @brief Assigns "valeur" to the j-th element of the i-th list with 0 <= i < get_nb_lists() and 0 <= j < get_list_size(i).
76 *
77 */
78template <typename _SIZE_>
80{
81 const int_t index = index_[i] + j;
82 assert(index < index_[i+1]);
83 valeurs_[index] = valeur;
84}
85
86/*! @brief Returns the j-th element of the i-th list with 0 <= i < get_nb_lists() and 0 <= j < get_list_size(i).
87 *
88 */
89template <typename _SIZE_>
91{
92 const int_t index = index_[i] + j;
93 assert(index < index_[i+1]);
94 const int_t val = valeurs_[index];
95 return val;
96}
97
98/*! @brief Returns the number of elements in list i.
99 *
100 */
101template <typename _SIZE_>
103{
104 return index_[i+1] - index_[i];
105}
106
107/*! @brief Returns the number of stored lists.
108 *
109 */
110template <typename _SIZE_>
112{
113 return index_.size_array() - 1;
114}
115
116using Static_Int_Lists = Static_Int_Lists_32_64<int>;
117using Static_Int_Lists_64 = Static_Int_Lists_32_64<trustIdType>;
118
119#endif
Class defining operators and methods for all reading operation in an input flow (file,...
Definition Entree.h:42
Base class for output streams.
Definition Sortie.h:52
This class allows storing lists of integers accessible in constant time.
void set(const ArrsOfInt_t &src)
Sortie & ecrire(Sortie &os) const
void copy_list_to_array(int_t i_liste, ArrOfInt_t &array) const
Copies the i-th list into the provided array. The array must be resizable.
const ArrOfInt_t & get_index() const
void set_value(int_t i_liste, int_t i_element, int_t valeur)
Assigns "valeur" to the j-th element of the i-th list with 0 <= i < get_nb_lists() and 0 <= j < get_l...
void set_index_data(const ArrOfInt_t &index, const ArrOfInt_t &data)
Replaces index and data arrays.
ArrsOfInt_T< _SIZE_ > ArrsOfInt_t
void reset()
Destroys all lists.
int_t get_list_size(int_t i_liste) const
Returns the number of elements in list i.
void trier_liste(int_t i)
Sorts the values of the i-th list in ascending order.
void set_list_sizes(const ArrOfInt_t &sizes)
Destroys existing lists and creates new ones.
int_t get_nb_lists() const
Returns the number of stored lists.
Entree & readOn(Entree &is)
ArrOfInt_T< _SIZE_ > ArrOfInt_t
Sortie & printOn(Sortie &os) const
void set_data(const ArrOfInt_t &data)
Replaces the values stored in all lists with those from the data array.
const ArrOfInt_t & get_data() const
int_t operator()(int_t i_liste, int_t i_element) const
Returns the j-th element of the i-th list with 0 <= i < get_nb_lists() and 0 <= j < get_list_size(i).