DOLFIN
DOLFIN C++ interface
Toggle main menu visibility
Loading...
Searching...
No Matches
dolfin
common
Set.h
1
// Copyright (C) 2009-2011 Garth N. Wells
2
//
3
// This file is part of DOLFIN.
4
//
5
// DOLFIN is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU Lesser General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
9
//
10
// DOLFIN is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public License
16
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17
//
18
// First added: 2009-08-09
19
// Last changed: 2011-01-05
20
21
#ifndef __DOLFIN_SET_H
22
#define __DOLFIN_SET_H
23
24
#include <algorithm>
25
#include <cstddef>
26
#include <vector>
27
28
namespace
dolfin
29
{
30
33
// and std::unordered_set in some cases.
34
35
template
<
typename
T>
36
class
Set
37
{
38
public
:
39
41
typedef
typename
std::vector<T>::iterator
iterator
;
43
typedef
typename
std::vector<T>::const_iterator
const_iterator
;
44
46
Set
() {}
47
49
Set
(std::vector<T>& x) : _x(x)
50
{ _x.clear(); }
51
53
Set
(
const
dolfin::Set<T>
& x) : _x(x._x) {}
54
56
~Set
() {}
57
59
iterator
find
(
const
T& x)
60
{
return
std::find(_x.begin(), _x.end(), x); }
61
63
const_iterator
find
(
const
T& x)
const
64
{
return
std::find(_x.begin(), _x.end(), x); }
65
67
bool
insert
(
const
T& x)
68
{
69
if
(
find
(x) == this->
end
() )
70
{
71
_x.push_back(x);
72
return
true
;
73
}
74
else
75
return
false
;
76
}
77
79
template
<
typename
InputIt>
80
void
insert
(
const
InputIt first,
const
InputIt last)
81
{
82
for
(InputIt position = first; position != last; ++position)
83
{
84
if
(std::find(_x.begin(), _x.end(), *position) == _x.end())
85
_x.push_back(*position);
86
}
87
}
88
90
const_iterator
begin
()
const
91
{
return
_x.begin(); }
92
94
const_iterator
end
()
const
95
{
return
_x.end(); }
96
98
std::size_t
size
()
const
99
{
return
_x.size(); }
100
102
void
erase
(
const
T& x)
103
{
104
iterator
p =
find
(x);
105
if
(p != _x.end())
106
_x.erase(p);
107
}
108
110
void
sort
()
111
{ std::sort(_x.begin(), _x.end()); }
112
114
void
clear
()
115
{ _x.clear(); }
116
118
T
operator[]
(std::size_t n)
const
119
{
return
_x[n]; }
120
122
const
std::vector<T>&
set
()
const
123
{
return
_x; }
124
126
std::vector<T>&
set
()
127
{
return
_x; }
128
129
private
:
130
131
std::vector<T> _x;
132
133
};
134
135
}
136
137
#endif
dolfin::Set
Definition
Set.h:37
dolfin::Set::clear
void clear()
Clear set.
Definition
Set.h:114
dolfin::Set::erase
void erase(const T &x)
Erase an entry.
Definition
Set.h:102
dolfin::Set::~Set
~Set()
Destructor.
Definition
Set.h:56
dolfin::Set::size
std::size_t size() const
Set size.
Definition
Set.h:98
dolfin::Set::find
const_iterator find(const T &x) const
Find entry in set and return an iterator to the entry (const).
Definition
Set.h:63
dolfin::Set::end
const_iterator end() const
Iterator to beyond end of Set.
Definition
Set.h:94
dolfin::Set::const_iterator
std::vector< T >::const_iterator const_iterator
Const iterator.
Definition
Set.h:43
dolfin::Set::Set
Set(const dolfin::Set< T > &x)
Copy constructor.
Definition
Set.h:53
dolfin::Set::Set
Set()
Create empty set.
Definition
Set.h:46
dolfin::Set::Set
Set(std::vector< T > &x)
Wrap std::vector as a set. Contents will be erased.
Definition
Set.h:49
dolfin::Set::set
std::vector< T > & set()
Return the vector that stores the data in the Set.
Definition
Set.h:126
dolfin::Set::iterator
std::vector< T >::iterator iterator
Iterator.
Definition
Set.h:41
dolfin::Set::set
const std::vector< T > & set() const
Return the vector that stores the data in the Set.
Definition
Set.h:122
dolfin::Set::begin
const_iterator begin() const
Iterator to start of Set.
Definition
Set.h:90
dolfin::Set::sort
void sort()
Sort set.
Definition
Set.h:110
dolfin::Set::operator[]
T operator[](std::size_t n) const
Index the nth entry in the set.
Definition
Set.h:118
dolfin::Set::find
iterator find(const T &x)
Find entry in set and return an iterator to the entry.
Definition
Set.h:59
dolfin::Set::insert
void insert(const InputIt first, const InputIt last)
Insert entries.
Definition
Set.h:80
dolfin::Set::insert
bool insert(const T &x)
Insert entry.
Definition
Set.h:67
dolfin
Definition
adapt.h:30
Generated by
1.17.0