MFEM  v4.5.2 Finite element discretization library
sets.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2023, Lawrence Livermore National Security, LLC. Produced
3 // LICENSE and NOTICE for details. LLNL-CODE-806117.
4 //
5 // This file is part of the MFEM library. For more information and source code
6 // availability visit https://mfem.org.
7 //
8 // MFEM is free software; you can redistribute it and/or modify it under the
9 // terms of the BSD-3 license. We welcome feedback and contributions, see file
10 // CONTRIBUTING.md for details.
11
12 #ifndef MFEM_SETS
13 #define MFEM_SETS
14
15 #include "../config/config.hpp"
16 #include "array.hpp"
17 #include "table.hpp"
18
19 namespace mfem
20 {
21
22 /// A set of integers
24 {
25 private:
26  Array<int> me;
27
28 public:
29  /// Create an empty set.
30  IntegerSet() { }
31
32  /// Create a copy of set 's'.
34
35  /// Create an integer set from C-array 'p' of 'n' integers.
36  IntegerSet(const int n, const int *p) { Recreate(n, p); }
37
38  /// Return the size of the set.
39  int Size() { return me.Size(); }
40
41  /// Return a reference to the sorted array of all the set entries.
42  operator Array<int>& () { return me; }
43
44  /// Return the value of the lowest element of the set.
45  int PickElement() { return me[0]; }
46
47  /// Return the value of a random element of the set.
48  int PickRandomElement();
49
50  /// Create a copy of set 's'.
52
53  /// Return 1 if the sets are equal and 0 otherwise.
54  int operator==(IntegerSet &s);
55
56  /** @brief Create an integer set from C-array 'p' of 'n' integers.
57  Overwrites any existing set data. */
58  void Recreate(const int n, const int *p);
59 };
60
61 /// List of integer sets
63 {
64 private:
65  Array<IntegerSet *> TheList;
66
67 public:
68
69  /// Return the number of integer sets in the list.
70  int Size() { return TheList.Size(); }
71
72  /// Return the value of the first element of the ith set.
73  int PickElementInSet(int i) { return TheList[i]->PickElement(); }
74
75  /// Return a random value from the ith set in the list.
76  int PickRandomElementInSet(int i) { return TheList[i]->PickRandomElement(); }
77
78  /** @brief Check to see if set 's' is in the list. If not append it to the
79  end of the list. Returns the index of the list where set 's' can be
80  found. */
81  int Insert(IntegerSet &s);
82
83  /** Return the index of the list where set 's' can be found. Returns -1 if
85  int Lookup(IntegerSet &s);
86
87  /// Write the list of sets into table 't'.
88  void AsTable(Table &t);
89
91 };
92
93 }
94
95 #endif
int Lookup(IntegerSet &s)
Definition: sets.cpp:104
void Recreate(const int n, const int *p)
Create an integer set from C-array &#39;p&#39; of &#39;n&#39; integers. Overwrites any existing set data...
Definition: sets.cpp:68
void AsTable(Table &t)
Write the list of sets into table &#39;t&#39;.
Definition: sets.cpp:116
IntegerSet(const int n, const int *p)
Create an integer set from C-array &#39;p&#39; of &#39;n&#39; integers.
Definition: sets.hpp:36
int PickRandomElement()
Return the value of a random element of the set.
Definition: sets.cpp:53
int PickElementInSet(int i)
Return the value of the first element of the ith set.
Definition: sets.hpp:73
int PickRandomElementInSet(int i)
Return a random value from the ith set in the list.
Definition: sets.hpp:76
int operator==(IntegerSet &s)
Return 1 if the sets are equal and 0 otherwise.
Definition: sets.cpp:37
int Insert(IntegerSet &s)
Check to see if set &#39;s&#39; is in the list. If not append it to the end of the list. Returns the index of...
Definition: sets.cpp:91
int Size()
Return the number of integer sets in the list.
Definition: sets.hpp:70
int Size()
Return the size of the set.
Definition: sets.hpp:39
IntegerSet()
Create an empty set.
Definition: sets.hpp:30
int PickElement()
Return the value of the lowest element of the set.
Definition: sets.hpp:45
IntegerSet & operator=(const IntegerSet &s)
Create a copy of set &#39;s&#39;.
Definition: sets.cpp:27
A set of integers.
Definition: sets.hpp:23
int Size() const
Return the logical size of the array.
Definition: array.hpp:141
RefCoord t[3]
RefCoord s[3]
List of integer sets.
Definition: sets.hpp:62