MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
sets.hpp
Go to the documentation of this file.
1 // Copyright (c) 2010-2020, Lawrence Livermore National Security, LLC. Produced
2 // at the Lawrence Livermore National Laboratory. All Rights reserved. See files
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  /// Return 1 if the sets are equal and 0 otherwise.
51  int operator==(IntegerSet &s);
52 
53  /** @brief Create an integer set from C-array 'p' of 'n' integers.
54  Overwrites any existing set data. */
55  void Recreate(const int n, const int *p);
56 };
57 
58 /// List of integer sets
60 {
61 private:
62  Array<IntegerSet *> TheList;
63 
64 public:
65 
66  /// Return the number of integer sets in the list.
67  int Size() { return TheList.Size(); }
68 
69  /// Return the value of the first element of the ith set.
70  int PickElementInSet(int i) { return TheList[i]->PickElement(); }
71 
72  /// Return a random value from the ith set in the list.
73  int PickRandomElementInSet(int i) { return TheList[i]->PickRandomElement(); }
74 
75  /** @brief Check to see if set 's' is in the list. If not append it to the
76  end of the list. Returns the index of the list where set 's' can be
77  found. */
78  int Insert(IntegerSet &s);
79 
80  /** Return the index of the list where set 's' can be found. Returns -1 if
81  not found. */
82  int Lookup(IntegerSet &s);
83 
84  /// Write the list of sets into table 't'.
85  void AsTable(Table &t);
86 
88 };
89 
90 }
91 
92 #endif
int Lookup(IntegerSet &s)
Definition: sets.cpp:95
int Size() const
Return the logical size of the array.
Definition: array.hpp:124
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:59
void AsTable(Table &t)
Write the list of sets into table &#39;t&#39;.
Definition: sets.cpp:107
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:44
int PickElementInSet(int i)
Return the value of the first element of the ith set.
Definition: sets.hpp:70
int PickRandomElementInSet(int i)
Return a random value from the ith set in the list.
Definition: sets.hpp:73
int operator==(IntegerSet &s)
Return 1 if the sets are equal and 0 otherwise.
Definition: sets.cpp:28
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:82
int Size()
Return the number of integer sets in the list.
Definition: sets.hpp:67
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
A set of integers.
Definition: sets.hpp:23
List of integer sets.
Definition: sets.hpp:59