Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
torch-sparse
Commits
2951b12d
Commit
2951b12d
authored
Jan 10, 2024
by
aiss
Browse files
push v0.6.18 version
parent
e8309f27
Changes
266
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
717 additions
and
0 deletions
+717
-0
third_party/parallel-hashmap/tests/parallel_flat_hash_set_test.cc
...rty/parallel-hashmap/tests/parallel_flat_hash_set_test.cc
+5
-0
third_party/parallel-hashmap/tests/parallel_hash_map_test.cc
third_party/parallel-hashmap/tests/parallel_hash_map_test.cc
+140
-0
third_party/parallel-hashmap/tests/parallel_hash_set_test.cc
third_party/parallel-hashmap/tests/parallel_hash_set_test.cc
+136
-0
third_party/parallel-hashmap/tests/parallel_node_hash_map_test.cc
...rty/parallel-hashmap/tests/parallel_node_hash_map_test.cc
+4
-0
third_party/parallel-hashmap/tests/parallel_node_hash_set_test.cc
...rty/parallel-hashmap/tests/parallel_node_hash_set_test.cc
+4
-0
third_party/parallel-hashmap/tests/raw_hash_set_allocator_test.cc
...rty/parallel-hashmap/tests/raw_hash_set_allocator_test.cc
+428
-0
No files found.
Too many changes to show.
To preserve performance only
266 of 266+
files are displayed.
Plain diff
Email patch
third_party/parallel-hashmap/tests/parallel_flat_hash_set_test.cc
0 → 100644
View file @
2951b12d
#define THIS_HASH_SET parallel_flat_hash_set
#define THIS_TEST_NAME ParallelFlatHashSet
#include "parallel_hash_set_test.cc"
third_party/parallel-hashmap/tests/parallel_hash_map_test.cc
0 → 100644
View file @
2951b12d
#ifndef THIS_HASH_MAP
#define THIS_HASH_MAP parallel_flat_hash_map
#define THIS_TEST_NAME ParallelFlatHashMap
#endif
#include "flat_hash_map_test.cc"
namespace
phmap
{
namespace
priv
{
namespace
{
TEST
(
THIS_TEST_NAME
,
IfContains
)
{
// ----------------
// test if_contains
// ----------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
7
},
{
2
,
9
}
};
const
Map
&
const_m
(
m
);
auto
val
=
0
;
auto
get_value
=
[
&
val
](
const
Map
::
value_type
&
v
)
{
val
=
v
.
second
;
};
EXPECT_TRUE
(
const_m
.
if_contains
(
2
,
get_value
));
EXPECT_EQ
(
val
,
9
);
EXPECT_FALSE
(
m
.
if_contains
(
3
,
get_value
));
}
TEST
(
THIS_TEST_NAME
,
ModifyIf
)
{
// --------------
// test modify_if
// --------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
7
},
{
2
,
9
}
};
auto
set_value
=
[](
Map
::
value_type
&
v
)
{
v
.
second
=
11
;
};
EXPECT_TRUE
(
m
.
modify_if
(
2
,
set_value
));
EXPECT_EQ
(
m
[
2
],
11
);
EXPECT_FALSE
(
m
.
modify_if
(
3
,
set_value
));
// because m[3] does not exist
}
TEST
(
THIS_TEST_NAME
,
TryEmplaceL
)
{
// ------------------
// test try_emplace_l
// ------------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
7
},
{
2
,
9
}
};
// overwrite an existing value
m
.
try_emplace_l
(
2
,
[](
Map
::
value_type
&
v
)
{
v
.
second
=
5
;
});
EXPECT_EQ
(
m
[
2
],
5
);
// insert a value that is not already present. Will be default initialised to 0 and lambda not called
m
.
try_emplace_l
(
3
,
[](
Map
::
value_type
&
v
)
{
v
.
second
=
6
;
},
// called only when key was already present
1
);
// argument to construct new value is key not present
EXPECT_EQ
(
m
[
3
],
1
);
// insert a value that is not already present, provide argument to value-construct it
m
.
try_emplace_l
(
4
,
[](
Map
::
value_type
&
)
{},
// called only when key was already present
999
);
// argument to construct new value is key not present
EXPECT_EQ
(
m
[
4
],
999
);
}
TEST
(
THIS_TEST_NAME
,
LazyEmplaceL
)
{
// --------------------
// test lazy_emplace_l
// --------------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
7
},
{
2
,
9
}
};
// insert a value that is not already present.
// right now m[5] does not exist
m
.
lazy_emplace_l
(
5
,
[](
Map
::
value_type
&
v
)
{
v
.
second
=
6
;
},
// called only when key was already present
[](
const
Map
::
constructor
&
ctor
)
{
ctor
(
5
,
13
);
});
// construct value_type in place when key not present
EXPECT_EQ
(
m
[
5
],
13
);
// change a value that is present. Currently m[5] == 13
m
.
lazy_emplace_l
(
5
,
[](
Map
::
value_type
&
v
)
{
v
.
second
=
6
;
},
// called only when key was already present
[](
const
Map
::
constructor
&
ctor
)
{
ctor
(
5
,
13
);
});
// construct value_type in place when key not present
EXPECT_EQ
(
m
[
5
],
6
);
}
TEST
(
THIS_TEST_NAME
,
EraseIf
)
{
// -------------
// test erase_if
// -------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
7
},
{
2
,
9
},
{
5
,
6
}
};
EXPECT_EQ
(
m
.
erase_if
(
9
,
[](
Map
::
value_type
&
v
)
{
assert
(
0
);
return
v
.
second
==
12
;
}),
false
);
// m[9] not present - lambda not called
EXPECT_EQ
(
m
.
erase_if
(
5
,
[](
Map
::
value_type
&
v
)
{
return
v
.
second
==
12
;
}),
false
);
// m[5] == 6, so erase not performed
EXPECT_EQ
(
m
[
5
],
6
);
EXPECT_EQ
(
m
.
erase_if
(
5
,
[](
Map
::
value_type
&
v
)
{
return
v
.
second
==
6
;
}),
true
);
// lambda returns true, so m[5] erased
EXPECT_EQ
(
m
[
5
],
0
);
}
TEST
(
THIS_TEST_NAME
,
ForEach
)
{
// -------------
// test for_each
// -------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
7
},
{
2
,
8
},
{
5
,
11
}
};
// increment all values by 1
m
.
for_each_m
([](
Map
::
value_type
&
pair
)
{
++
pair
.
second
;
});
int
counter
=
0
;
m
.
for_each
([
&
counter
](
const
Map
::
value_type
&
pair
)
{
++
counter
;
EXPECT_EQ
(
pair
.
first
+
7
,
pair
.
second
);
});
EXPECT_EQ
(
counter
,
3
);
}
TEST
(
THIS_TEST_NAME
,
EmplaceSingle
)
{
// --------------------
// test emplace_single
// --------------------
using
Map
=
ThisMap
<
int
,
int
>
;
Map
m
=
{
{
1
,
4
},
{
11
,
4
}
};
// emplace_single insert a value if not already present, else removes it
for
(
int
i
=
0
;
i
<
12
;
++
i
)
m
.
emplace_single
(
i
,
[
i
](
const
Map
::
constructor
&
ctor
)
{
ctor
(
i
,
4
);
});
EXPECT_EQ
(
m
.
count
(
0
),
1
);
EXPECT_EQ
(
m
.
count
(
1
),
0
);
EXPECT_EQ
(
m
.
count
(
2
),
1
);
EXPECT_EQ
(
m
.
count
(
11
),
0
);
}
}
// namespace
}
// namespace priv
}
// namespace phmap
third_party/parallel-hashmap/tests/parallel_hash_set_test.cc
0 → 100644
View file @
2951b12d
#ifndef THIS_HASH_SET
#define THIS_HASH_SET parallel_flat_hash_set
#define THIS_TEST_NAME ParallelFlatHashSet
#endif
#include "flat_hash_set_test.cc"
namespace
phmap
{
namespace
priv
{
namespace
{
struct
Entry
{
Entry
(
int
k
,
int
v
=
0
)
:
key
(
k
),
value
(
v
)
{}
bool
operator
==
(
const
Entry
&
o
)
const
{
return
key
==
o
.
key
;
// not checking value
}
// Demonstrates how to provide the hash function as a friend member function of the class
// This can be used as an alternative to providing a std::hash<Person> specialization
// --------------------------------------------------------------------------------------
friend
size_t
hash_value
(
const
Entry
&
p
)
{
return
phmap
::
HashState
().
combine
(
0
,
p
.
key
);
// not checking value
}
int
key
;
int
value
;
};
TEST
(
THIS_TEST_NAME
,
IfContains
)
{
// ----------------
// test if_contains
// ----------------
using
Set
=
phmap
::
THIS_HASH_SET
<
Entry
>
;
Set
m
=
{
{
1
,
7
},
{
2
,
9
}
};
const
Set
&
const_m
(
m
);
auto
val
=
0
;
auto
get_value
=
[
&
val
](
const
Set
::
value_type
&
v
)
{
val
=
v
.
value
;
};
EXPECT_TRUE
(
const_m
.
if_contains
(
Entry
{
2
},
get_value
));
EXPECT_EQ
(
val
,
9
);
EXPECT_FALSE
(
m
.
if_contains
(
Entry
{
3
},
get_value
));
}
TEST
(
THIS_TEST_NAME
,
ModifyIf
)
{
// --------------
// test modify_if
// --------------
using
Set
=
phmap
::
THIS_HASH_SET
<
Entry
>
;
Set
m
=
{
{
1
,
7
},
{
2
,
9
}
};
auto
set_value
=
[](
Set
::
value_type
&
v
)
{
v
.
value
=
11
;
};
EXPECT_TRUE
(
m
.
modify_if
(
Entry
{
2
},
set_value
));
auto
val
=
0
;
auto
get_value
=
[
&
val
](
const
Set
::
value_type
&
v
)
{
val
=
v
.
value
;
};
EXPECT_TRUE
(
m
.
if_contains
(
Entry
{
2
},
get_value
));
EXPECT_EQ
(
val
,
11
);
EXPECT_FALSE
(
m
.
modify_if
(
Entry
{
3
},
set_value
));
// because m[3] does not exist
}
TEST
(
THIS_TEST_NAME
,
LazyEmplaceL
)
{
// --------------------
// test lazy_emplace_l
// --------------------
using
Set
=
phmap
::
THIS_HASH_SET
<
Entry
>
;
Set
m
=
{
{
1
,
7
},
{
2
,
9
}
};
// insert a value that is not already present.
// right now m[5] does not exist
m
.
lazy_emplace_l
(
Entry
{
5
},
[](
Set
::
value_type
&
v
)
{
v
.
value
=
6
;
},
// called only when key was already present
[](
const
Set
::
constructor
&
ctor
)
{
ctor
(
5
,
13
);
});
// construct value_type in place when key not present
EXPECT_EQ
(
m
.
find
(
Entry
{
5
})
->
value
,
13
);
// change a value that is present.
m
.
lazy_emplace_l
(
Entry
{
5
},
[](
Set
::
value_type
&
v
)
{
v
.
value
=
6
;
},
// called only when key was already present
[](
const
Set
::
constructor
&
ctor
)
{
ctor
(
5
,
13
);
});
// construct value_type in place when key not present
EXPECT_EQ
(
m
.
find
(
Entry
{
5
})
->
value
,
6
);
}
TEST
(
THIS_TEST_NAME
,
EraseIf
)
{
// -------------
// test erase_if
// -------------
using
Set
=
phmap
::
THIS_HASH_SET
<
Entry
>
;
Set
m
=
{
{
1
,
7
},
{
2
,
9
},
{
5
,
6
}
};
EXPECT_EQ
(
m
.
erase_if
(
Entry
{
9
},
[](
Set
::
value_type
&
v
)
{
assert
(
0
);
return
v
.
value
==
12
;
}),
false
);
// m[9] not present - lambda not called
EXPECT_EQ
(
m
.
erase_if
(
Entry
{
5
},
[](
Set
::
value_type
&
v
)
{
return
v
.
value
==
12
;
}),
false
);
// m[5] == 6, so erase not performed
EXPECT_EQ
(
m
.
find
(
Entry
{
5
})
->
value
,
6
);
EXPECT_EQ
(
m
.
erase_if
(
Entry
{
5
},
[](
Set
::
value_type
&
v
)
{
return
v
.
value
==
6
;
}),
true
);
// lambda returns true, so m[5] erased
EXPECT_EQ
(
m
.
find
(
Entry
{
5
}),
m
.
end
());
}
TEST
(
THIS_TEST_NAME
,
ForEach
)
{
// -------------
// test for_each
// -------------
using
Set
=
phmap
::
THIS_HASH_SET
<
Entry
>
;
Set
m
=
{
{
1
,
7
},
{
2
,
8
},
{
5
,
11
}
};
int
counter
=
0
;
m
.
for_each
([
&
counter
](
const
Set
::
value_type
&
v
)
{
++
counter
;
EXPECT_EQ
(
v
.
key
+
6
,
v
.
value
);
});
EXPECT_EQ
(
counter
,
3
);
}
TEST
(
THIS_TEST_NAME
,
EmplaceSingle
)
{
using
Set
=
phmap
::
THIS_HASH_SET
<
int
>
;
// --------------------
// test emplace_single
// --------------------
Set
m
=
{
1
,
11
};
// emplace_single insert a value if not already present, else removes it
for
(
int
i
=
0
;
i
<
12
;
++
i
)
m
.
emplace_single
(
i
,
[
i
](
const
Set
::
constructor
&
ctor
)
{
ctor
(
i
);
});
EXPECT_EQ
(
m
.
count
(
0
),
1
);
EXPECT_EQ
(
m
.
count
(
1
),
0
);
EXPECT_EQ
(
m
.
count
(
2
),
1
);
EXPECT_EQ
(
m
.
count
(
11
),
0
);
}
}
// namespace
}
// namespace priv
}
// namespace phmap
third_party/parallel-hashmap/tests/parallel_node_hash_map_test.cc
0 → 100644
View file @
2951b12d
#define THIS_HASH_MAP parallel_node_hash_map
#define THIS_TEST_NAME ParallelNodeHashMap
#include "parallel_hash_map_test.cc"
third_party/parallel-hashmap/tests/parallel_node_hash_set_test.cc
0 → 100644
View file @
2951b12d
#define THIS_HASH_SET parallel_node_hash_set
#define THIS_TEST_NAME ParallelNodeHashSet
#include "node_hash_set_test.cc"
third_party/parallel-hashmap/tests/raw_hash_set_allocator_test.cc
0 → 100644
View file @
2951b12d
// Copyright 2018 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <limits>
#include <scoped_allocator>
#include "gtest/gtest.h"
#include "parallel_hashmap/phmap.h"
#include "tracked.h"
namespace
phmap
{
namespace
priv
{
namespace
{
enum
AllocSpec
{
kPropagateOnCopy
=
1
,
kPropagateOnMove
=
2
,
kPropagateOnSwap
=
4
,
};
struct
AllocState
{
size_t
num_allocs
=
0
;
std
::
set
<
void
*>
owned
;
};
template
<
class
T
,
int
Spec
=
kPropagateOnCopy
|
kPropagateOnMove
|
kPropagateOnSwap
>
class
CheckedAlloc
{
public:
template
<
class
,
int
>
friend
class
CheckedAlloc
;
using
value_type
=
T
;
CheckedAlloc
()
{}
explicit
CheckedAlloc
(
size_t
id
)
:
id_
(
id
)
{}
CheckedAlloc
(
const
CheckedAlloc
&
)
=
default
;
CheckedAlloc
&
operator
=
(
const
CheckedAlloc
&
)
=
default
;
template
<
class
U
>
CheckedAlloc
(
const
CheckedAlloc
<
U
,
Spec
>&
that
)
:
id_
(
that
.
id_
),
state_
(
that
.
state_
)
{}
template
<
class
U
>
struct
rebind
{
using
other
=
CheckedAlloc
<
U
,
Spec
>
;
};
using
propagate_on_container_copy_assignment
=
std
::
integral_constant
<
bool
,
(
Spec
&
kPropagateOnCopy
)
!=
0
>
;
using
propagate_on_container_move_assignment
=
std
::
integral_constant
<
bool
,
(
Spec
&
kPropagateOnMove
)
!=
0
>
;
using
propagate_on_container_swap
=
std
::
integral_constant
<
bool
,
(
Spec
&
kPropagateOnSwap
)
!=
0
>
;
CheckedAlloc
select_on_container_copy_construction
()
const
{
if
(
Spec
&
kPropagateOnCopy
)
return
*
this
;
return
{};
}
T
*
allocate
(
size_t
n
)
{
T
*
ptr
=
std
::
allocator
<
T
>
().
allocate
(
n
);
track_alloc
(
ptr
);
return
ptr
;
}
void
deallocate
(
T
*
ptr
,
size_t
n
)
{
memset
(
ptr
,
0
,
n
*
sizeof
(
T
));
// The freed memory must be unpoisoned.
track_dealloc
(
ptr
);
return
std
::
allocator
<
T
>
().
deallocate
(
ptr
,
n
);
}
friend
bool
operator
==
(
const
CheckedAlloc
&
a
,
const
CheckedAlloc
&
b
)
{
return
a
.
id_
==
b
.
id_
;
}
friend
bool
operator
!=
(
const
CheckedAlloc
&
a
,
const
CheckedAlloc
&
b
)
{
return
!
(
a
==
b
);
}
size_t
num_allocs
()
const
{
return
state_
->
num_allocs
;
}
void
swap
(
CheckedAlloc
&
that
)
{
using
std
::
swap
;
swap
(
id_
,
that
.
id_
);
swap
(
state_
,
that
.
state_
);
}
friend
void
swap
(
CheckedAlloc
&
a
,
CheckedAlloc
&
b
)
{
a
.
swap
(
b
);
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
o
,
const
CheckedAlloc
&
a
)
{
return
o
<<
"alloc("
<<
a
.
id_
<<
")"
;
}
private:
void
track_alloc
(
void
*
ptr
)
{
AllocState
*
state
=
state_
.
get
();
++
state
->
num_allocs
;
if
(
!
state
->
owned
.
insert
(
ptr
).
second
)
ADD_FAILURE
()
<<
*
this
<<
" got previously allocated memory: "
<<
ptr
;
}
void
track_dealloc
(
void
*
ptr
)
{
if
(
state_
->
owned
.
erase
(
ptr
)
!=
1
)
ADD_FAILURE
()
<<
*
this
<<
" deleting memory owned by another allocator: "
<<
ptr
;
}
size_t
id_
=
std
::
numeric_limits
<
size_t
>::
max
();
std
::
shared_ptr
<
AllocState
>
state_
=
std
::
make_shared
<
AllocState
>
();
};
struct
Identity
{
int32_t
operator
()(
int32_t
v
)
const
{
return
v
;
}
};
struct
Policy
{
using
slot_type
=
Tracked
<
int32_t
>
;
using
init_type
=
Tracked
<
int32_t
>
;
using
key_type
=
int32_t
;
template
<
class
allocator_type
,
class
...
Args
>
static
void
construct
(
allocator_type
*
alloc
,
slot_type
*
slot
,
Args
&&
...
args
)
{
std
::
allocator_traits
<
allocator_type
>::
construct
(
*
alloc
,
slot
,
std
::
forward
<
Args
>
(
args
)...);
}
template
<
class
allocator_type
>
static
void
destroy
(
allocator_type
*
alloc
,
slot_type
*
slot
)
{
std
::
allocator_traits
<
allocator_type
>::
destroy
(
*
alloc
,
slot
);
}
template
<
class
allocator_type
>
static
void
transfer
(
allocator_type
*
alloc
,
slot_type
*
new_slot
,
slot_type
*
old_slot
)
{
construct
(
alloc
,
new_slot
,
std
::
move
(
*
old_slot
));
destroy
(
alloc
,
old_slot
);
}
template
<
class
F
>
static
auto
apply
(
F
&&
f
,
int32_t
v
)
->
decltype
(
std
::
forward
<
F
>
(
f
)(
v
,
v
))
{
return
std
::
forward
<
F
>
(
f
)(
v
,
v
);
}
template
<
class
F
>
static
auto
apply
(
F
&&
f
,
const
slot_type
&
v
)
->
decltype
(
std
::
forward
<
F
>
(
f
)(
v
.
val
(),
v
))
{
return
std
::
forward
<
F
>
(
f
)(
v
.
val
(),
v
);
}
template
<
class
F
>
static
auto
apply
(
F
&&
f
,
slot_type
&&
v
)
->
decltype
(
std
::
forward
<
F
>
(
f
)(
v
.
val
(),
std
::
move
(
v
)))
{
return
std
::
forward
<
F
>
(
f
)(
v
.
val
(),
std
::
move
(
v
));
}
static
slot_type
&
element
(
slot_type
*
slot
)
{
return
*
slot
;
}
};
template
<
int
Spec
>
struct
PropagateTest
:
public
::
testing
::
Test
{
using
Alloc
=
CheckedAlloc
<
Tracked
<
int32_t
>
,
Spec
>
;
using
Table
=
raw_hash_set
<
Policy
,
Identity
,
std
::
equal_to
<
int32_t
>
,
Alloc
>
;
PropagateTest
()
{
EXPECT_EQ
(
a1
,
t1
.
get_allocator
());
EXPECT_NE
(
a2
,
t1
.
get_allocator
());
}
Alloc
a1
=
Alloc
(
1
);
Table
t1
=
Table
(
0
,
a1
);
Alloc
a2
=
Alloc
(
2
);
};
using
PropagateOnAll
=
PropagateTest
<
kPropagateOnCopy
|
kPropagateOnMove
|
kPropagateOnSwap
>
;
using
NoPropagateOnCopy
=
PropagateTest
<
kPropagateOnMove
|
kPropagateOnSwap
>
;
using
NoPropagateOnMove
=
PropagateTest
<
kPropagateOnCopy
|
kPropagateOnSwap
>
;
TEST_F
(
PropagateOnAll
,
Empty
)
{
EXPECT_EQ
(
0
,
a1
.
num_allocs
());
}
TEST_F
(
PropagateOnAll
,
InsertAllocates
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
InsertDecomposes
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
EXPECT_FALSE
(
t1
.
insert
(
0
).
second
);
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
RehashMoves
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
EXPECT_EQ
(
0
,
it
->
num_moves
());
t1
.
rehash
(
2
*
t1
.
capacity
());
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
it
=
t1
.
find
(
0
);
EXPECT_EQ
(
1
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
CopyConstructor
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
t1
);
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnCopy
,
CopyConstructor
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
t1
);
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
u
.
get_allocator
().
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
CopyConstructorWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
t1
,
a1
);
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnCopy
,
CopyConstructorWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
t1
,
a1
);
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
CopyConstructorWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
t1
,
a2
);
EXPECT_EQ
(
a2
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
a2
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnCopy
,
CopyConstructorWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
t1
,
a2
);
EXPECT_EQ
(
a2
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
a2
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
MoveConstructor
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
std
::
move
(
t1
));
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnMove
,
MoveConstructor
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
std
::
move
(
t1
));
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
MoveConstructorWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
std
::
move
(
t1
),
a1
);
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnMove
,
MoveConstructorWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
std
::
move
(
t1
),
a1
);
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
MoveConstructorWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
std
::
move
(
t1
),
a2
);
it
=
u
.
find
(
0
);
EXPECT_EQ
(
a2
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
a2
.
num_allocs
());
EXPECT_EQ
(
1
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnMove
,
MoveConstructorWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
std
::
move
(
t1
),
a2
);
it
=
u
.
find
(
0
);
EXPECT_EQ
(
a2
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
a2
.
num_allocs
());
EXPECT_EQ
(
1
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
CopyAssignmentWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a1
);
u
=
t1
;
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnCopy
,
CopyAssignmentWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a1
);
u
=
t1
;
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
CopyAssignmentWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a2
);
u
=
t1
;
EXPECT_EQ
(
a1
,
u
.
get_allocator
());
EXPECT_EQ
(
2
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
a2
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnCopy
,
CopyAssignmentWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a2
);
u
=
t1
;
EXPECT_EQ
(
a2
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
a2
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
1
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
MoveAssignmentWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a1
);
u
=
std
::
move
(
t1
);
EXPECT_EQ
(
a1
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnMove
,
MoveAssignmentWithSameAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a1
);
u
=
std
::
move
(
t1
);
EXPECT_EQ
(
a1
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
MoveAssignmentWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a2
);
u
=
std
::
move
(
t1
);
EXPECT_EQ
(
a1
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
a2
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
NoPropagateOnMove
,
MoveAssignmentWithDifferentAlloc
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a2
);
u
=
std
::
move
(
t1
);
it
=
u
.
find
(
0
);
EXPECT_EQ
(
a2
,
u
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
1
,
a2
.
num_allocs
());
EXPECT_EQ
(
1
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
TEST_F
(
PropagateOnAll
,
Swap
)
{
auto
it
=
t1
.
insert
(
0
).
first
;
Table
u
(
0
,
a2
);
u
.
swap
(
t1
);
EXPECT_EQ
(
a1
,
u
.
get_allocator
());
EXPECT_EQ
(
a2
,
t1
.
get_allocator
());
EXPECT_EQ
(
1
,
a1
.
num_allocs
());
EXPECT_EQ
(
0
,
a2
.
num_allocs
());
EXPECT_EQ
(
0
,
it
->
num_moves
());
EXPECT_EQ
(
0
,
it
->
num_copies
());
}
}
// namespace
}
// namespace priv
}
// namespace phmap
Prev
1
…
10
11
12
13
14
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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