23 static const char*
Name() {
return "TestTraits"; }
27 return String::Cast(obj).Equals(
key);
31 return a.IsString() &&
b.IsString() &&
32 String::Cast(
a).Equals(String::Cast(
b));
38template <
typename Table>
41 intptr_t num_entries =
table.NumEntries();
42 intptr_t num_unused =
table.NumUnused();
43 intptr_t num_occupied =
table.NumOccupied();
44 intptr_t num_deleted =
table.NumDeleted();
45 for (intptr_t
i = 0;
i < num_entries; ++
i) {
47 num_unused -=
table.IsUnused(
i);
48 num_occupied -=
table.IsOccupied(
i);
49 num_deleted -=
table.IsDeleted(
i);
51 EXPECT_EQ(0, num_unused);
52 EXPECT_EQ(0, num_occupied);
53 EXPECT_EQ(0, num_deleted);
60 EXPECT_LE(5,
table.NumEntries());
61 EXPECT_EQ(0,
table.NumOccupied());
63 EXPECT_EQ(-1,
table.FindKey(
"a"));
66 intptr_t a_entry = -1;
67 EXPECT(!
table.FindKeyOrDeletedOrUnused(
"a", &a_entry));
68 EXPECT_NE(-1, a_entry);
70 table.InsertKey(a_entry,
a);
71 EXPECT_EQ(1,
table.NumOccupied());
73 EXPECT_EQ(a_entry,
table.FindKey(
"a"));
74 EXPECT_EQ(-1,
table.FindKey(
"b"));
75 intptr_t a_entry_again = -1;
76 EXPECT(
table.FindKeyOrDeletedOrUnused(
"a", &a_entry_again));
77 EXPECT_EQ(a_entry, a_entry_again);
78 intptr_t b_entry = -1;
79 EXPECT(!
table.FindKeyOrDeletedOrUnused(
"b", &b_entry));
81 table.InsertKey(b_entry,
b);
82 EXPECT_EQ(2,
table.NumOccupied());
86 table.DeleteEntry(a_entry);
87 EXPECT_EQ(1,
table.NumOccupied());
89 EXPECT_EQ(-1,
table.FindKey(
"a"));
90 EXPECT_EQ(b_entry,
table.FindKey(
"b"));
91 intptr_t c_entry = -1;
92 EXPECT(!
table.FindKeyOrDeletedOrUnused(
"c", &c_entry));
94 table.InsertKey(c_entry, c);
95 EXPECT_EQ(2,
table.NumOccupied());
97 EXPECT_EQ(c_entry,
table.FindKey(
"c"));
102 EXPECT(!
table.FindKeyOrDeletedOrUnused(
"d", &entry));
104 table.InsertKey(entry, k);
105 EXPECT(!
table.FindKeyOrDeletedOrUnused(
"e", &entry));
107 table.InsertKey(entry, k);
108 EXPECT(!
table.FindKeyOrDeletedOrUnused(
"f", &entry));
110 table.InsertKey(entry, k);
111 EXPECT_EQ(5,
table.NumOccupied());
119 for (intptr_t
i = 0;
i < str.
Length(); ++
i) {
128template <
typename Set>
135 EXPECT_EQ(
static_cast<intptr_t
>(expected.size()), keys.
Length());
136 std::vector<std::string> expected_vec(expected.begin(), expected.end());
138 for (uintptr_t
i = 0;
i < expected_vec.size(); ++
i) {
139 EXPECT(actual.ContainsKey(expected_vec[
i].c_str()));
142 std::vector<std::string> actual_vec;
144 for (
int i = 0;
i < keys.
Length(); ++
i) {
149 std::sort(actual_vec.begin(), actual_vec.end());
152 std::equal(actual_vec.begin(), actual_vec.end(), expected_vec.begin()));
158template <
typename Map>
162 intptr_t expected_size = expected.size();
166 EXPECT_EQ(expected_size * 2, entries.
Length());
167 std::vector<std::pair<std::string, int> > expected_vec(expected.begin(),
171 for (uintptr_t
i = 0;
i < expected_vec.size(); ++
i) {
172 std::string
key = expected_vec[
i].first;
174 value ^= actual.GetOrNull(
key.c_str());
175 EXPECT_EQ(expected_vec[
i].second,
value.Value());
181 std::vector<std::string> actual_vec;
183 for (
int i = 0;
i < expected_size; ++
i) {
187 EXPECT_EQ(expected_vec[
i].second,
value.Value());
191template <
typename Set>
192void TestSet(intptr_t initial_capacity,
bool ordered) {
193 std::set<std::string> expected;
194 Set actual(HashTables::New<Set>(initial_capacity));
201 for (
int i = 0;
i < 2; ++
i) {
202 for (
char ch =
'a'; ch <=
'z'; ++ch) {
203 std::string
key(
'z' - ch + 1, ch);
204 expected.insert(
key);
206 EXPECT_EQ((
i != 0), present);
212 EXPECT_EQ(0, actual.NumOccupied());
216template <
typename Map>
217void TestMap(intptr_t initial_capacity,
bool ordered) {
218 std::map<std::string, int> expected;
219 Map actual(HashTables::New<Map>(initial_capacity));
226 for (
int i = 0;
i < 2; ++
i) {
227 for (
char ch =
'a'; ch <=
'z'; ++ch) {
228 int length =
'z' - ch + 1;
236 EXPECT_EQ((
i != 0), present);
242 EXPECT_EQ(0, actual.NumOccupied());
247 for (intptr_t initial_capacity = 0; initial_capacity < 32;
248 ++initial_capacity) {
254 for (intptr_t initial_capacity = 0; initial_capacity < 32;
255 ++initial_capacity) {
256 TestMap<UnorderedHashMap<TestTraits> >(initial_capacity,
false);
static bool equal(const SkBitmap &a, const SkBitmap &b)
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
ObjectPtr At(intptr_t index) const
static ArrayPtr ToArray(const Table &table, bool include_payload)
static SmiPtr New(intptr_t value)
bool IsOneByteString() const
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
uint16_t CharAt(intptr_t index) const
static bool IsMatch(const Object &a, const Object &b)
static bool ReportStats()
static uword Hash(const char *key)
static bool IsMatch(const char *key, const Object &obj)
static const char * Name()
static ObjectPtr NewKey(const char *key)
static uword Hash(const Object &obj)
static Thread * Current()
void TestMap(intptr_t initial_capacity, bool ordered)
std::string ToStdString(const String &str)
void VerifyStringSetsEqual(const std::set< std::string > &expected, const Set &actual, bool ordered)
ISOLATE_UNIT_TEST_CASE(StackAllocatedDestruction)
void Validate(const Table &table)
void VerifyStringMapsEqual(const std::map< std::string, int > &expected, const Map &actual, bool ordered)
void TestSet(IntKeyHash hash, int size)
SK_API sk_sp< PrecompileColorFilter > Table()