Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Development
openfoam
Commits
990a9e7f
Commit
990a9e7f
authored
Jan 09, 2009
by
Mark Olesen
Browse files
added HashTable::erase(const HashTable&) method
parent
92c88521
Changes
7
Hide whitespace changes
Inline
Side-by-side
applications/test/HashTable/hashTableTest.C
View file @
990a9e7f
...
...
@@ -100,12 +100,12 @@ int main()
<<
"
\n
table2"
<<
table1
<<
nl
<<
"
\n
table3"
<<
table3
<<
nl
;
Info
<<
"
\n
delet
e table2"
<<
nl
;
Info
<<
"
\n
eras
e table2
by iterator
"
<<
nl
;
forAllIter
(
HASHTABLE_CLASS
<
double
>
,
table2
,
iter
)
{
Info
<<
"
delet
ing "
<<
iter
.
key
()
<<
" => "
<<
iter
()
<<
" ... "
;
Info
<<
"
eras
ing "
<<
iter
.
key
()
<<
" => "
<<
iter
()
<<
" ... "
;
table2
.
erase
(
iter
);
Info
<<
"
delet
ed"
<<
endl
;
Info
<<
"
eras
ed"
<<
endl
;
}
Info
<<
"
\n
table1"
<<
table1
<<
nl
...
...
@@ -134,6 +134,24 @@ int main()
table1
.
erase
(
table1
.
begin
());
Info
<<
"removed an element - test table1 != table3 : "
<<
(
table1
!=
table3
)
<<
nl
;
// insert a few things into table2
table2
.
set
(
"ada"
,
14
.
0
);
table2
.
set
(
"aeq"
,
15
.
0
);
table2
.
set
(
"aaw"
,
16
.
0
);
table2
.
set
(
"abs"
,
17
.
0
);
table2
.
set
(
"adx"
,
20
.
0
);
Info
<<
"
\n
table1"
<<
table1
<<
nl
<<
"
\n
table2"
<<
table2
<<
nl
;
label
nErased
=
table1
.
erase
(
table2
);
Info
<<
"
\n
erase table2 keys from table1 (removed "
<<
nErased
<<
" elements)"
<<
nl
<<
"
\n
table1"
<<
table1
<<
nl
<<
"
\n
table2"
<<
table2
<<
nl
;
Info
<<
"
\n
clearStorage table3 ... "
;
table3
.
clearStorage
();
...
...
applications/test/StaticHashTable/staticHashTableTest.C
View file @
990a9e7f
...
...
@@ -100,13 +100,13 @@ int main()
<<
"
\n
table2"
<<
table1
<<
nl
<<
"
\n
table3"
<<
table3
<<
nl
;
Info
<<
"
\n
delet
e table2"
<<
nl
;
forAllIter
(
HASHTABLE_CLASS
<
double
>
,
table2
,
iter
)
{
Info
<<
"
delet
ing "
<<
iter
.
key
()
<<
" => "
<<
iter
()
<<
" ... "
;
table2
.
erase
(
iter
);
Info
<<
"
delet
ed"
<<
endl
;
}
Info
<<
"
\n
eras
e table2
by iterator
"
<<
nl
;
forAllIter
(
HASHTABLE_CLASS
<
double
>
,
table2
,
iter
)
{
Info
<<
"
eras
ing "
<<
iter
.
key
()
<<
" => "
<<
iter
()
<<
" ... "
;
table2
.
erase
(
iter
);
Info
<<
"
eras
ed"
<<
endl
;
}
Info
<<
"
\n
table1"
<<
table1
<<
nl
<<
"
\n
table2"
<<
table2
<<
nl
...
...
@@ -134,6 +134,24 @@ int main()
table1
.
erase
(
table1
.
begin
());
Info
<<
"removed an element - test table1 != table3 : "
<<
(
table1
!=
table3
)
<<
nl
;
// insert a few things into table2
table2
.
set
(
"ada"
,
14
.
0
);
table2
.
set
(
"aeq"
,
15
.
0
);
table2
.
set
(
"aaw"
,
16
.
0
);
table2
.
set
(
"abs"
,
17
.
0
);
table2
.
set
(
"adx"
,
20
.
0
);
Info
<<
"
\n
table1"
<<
table1
<<
nl
<<
"
\n
table2"
<<
table2
<<
nl
;
label
nErased
=
table1
.
erase
(
table2
);
Info
<<
"
\n
erase table2 keys from table1 (removed "
<<
nErased
<<
" elements)"
<<
nl
<<
"
\n
table1"
<<
table1
<<
nl
<<
"
\n
table2"
<<
table2
<<
nl
;
Info
<<
"
\n
clearStorage table3 ... "
;
table3
.
clearStorage
();
...
...
@@ -144,5 +162,4 @@ int main()
return
0
;
}
// ************************************************************************* //
src/OpenFOAM/containers/HashTables/HashSet/HashSet.C
View file @
990a9e7f
...
...
@@ -126,6 +126,7 @@ void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
}
// same as HashTable::erase()
template
<
class
Key
,
class
Hash
>
void
Foam
::
HashSet
<
Key
,
Hash
>::
operator
-=
(
const
HashSet
<
Key
,
Hash
>&
rhs
)
{
...
...
src/OpenFOAM/containers/HashTables/HashTable/HashTable.C
View file @
990a9e7f
...
...
@@ -388,11 +388,11 @@ bool Foam::HashTable<T, Key, Hash>::erase(const iterator& cit)
template
<
class
T
,
class
Key
,
class
Hash
>
bool
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
erase
(
const
Key
&
key
)
{
iterator
it
=
find
(
key
);
iterator
fnd
=
find
(
key
);
if
(
it
!=
end
())
if
(
fnd
!=
end
())
{
return
erase
(
it
);
return
erase
(
fnd
);
}
else
{
...
...
@@ -401,6 +401,28 @@ bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
}
template
<
class
T
,
class
Key
,
class
Hash
>
Foam
::
label
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
erase
(
const
HashTable
<
T
,
Key
,
Hash
>&
rhs
)
{
label
count
=
0
;
// Remove rhs elements from this table
// NOTE: could optimize depending on which hash is smaller
for
(
iterator
iter
=
this
->
begin
();
iter
!=
this
->
end
();
++
iter
)
{
if
(
rhs
.
found
(
iter
.
key
())
&&
erase
(
iter
))
{
count
++
;
}
}
return
count
;
}
template
<
class
T
,
class
Key
,
class
Hash
>
void
Foam
::
HashTable
<
T
,
Key
,
Hash
>::
resize
(
const
label
newSize
)
{
...
...
src/OpenFOAM/containers/HashTables/HashTable/HashTable.H
View file @
990a9e7f
...
...
@@ -200,6 +200,10 @@ public:
//- Erase an hashedEntry specified by given key if in table
bool
erase
(
const
Key
&
);
//- Remove entries in the given HashTable from this HashTable
// Return the number of elements removed
label
erase
(
const
HashTable
<
T
,
Key
,
Hash
>&
);
//- Resize the hash table for efficiency
void
resize
(
const
label
newSize
);
...
...
src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.C
View file @
990a9e7f
...
...
@@ -346,6 +346,28 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const Key& key)
}
template
<
class
T
,
class
Key
,
class
Hash
>
Foam
::
label
Foam
::
StaticHashTable
<
T
,
Key
,
Hash
>::
erase
(
const
StaticHashTable
<
T
,
Key
,
Hash
>&
rhs
)
{
label
count
=
0
;
// Remove rhs elements from this table
// NOTE: could optimize depending on which hash is smaller
for
(
iterator
iter
=
this
->
begin
();
iter
!=
this
->
end
();
++
iter
)
{
if
(
rhs
.
found
(
iter
.
key
())
&&
erase
(
iter
))
{
count
++
;
}
}
return
count
;
}
template
<
class
T
,
class
Key
,
class
Hash
>
void
Foam
::
StaticHashTable
<
T
,
Key
,
Hash
>::
resize
(
const
label
newSize
)
{
...
...
src/OpenFOAM/containers/HashTables/StaticHashTable/StaticHashTable.H
View file @
990a9e7f
...
...
@@ -196,6 +196,10 @@ public:
//- Resize the hash table for efficiency
void
resize
(
const
label
newSize
);
//- Remove entries in the given hash table from this hash table
// Return the number of elements removed
label
erase
(
const
StaticHashTable
<
T
,
Key
,
Hash
>&
);
//- Clear all entries from table
void
clear
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment