mirror of
https://github.com/VectorCamp/vectorscan.git
synced 2025-09-29 19:24:25 +03:00
util: switch from Boost to std::unordered set/map
This commit replaces the ue2::unordered_{set,map} types with their STL versions, with some new hashing utilities in util/hash.h. The new types ue2_unordered_set<T> and ue2_unordered_map<Key, T> default to using the ue2_hasher. The header util/ue2_containers.h has been removed, and the flat_set/map containers moved to util/flat_containers.h.
This commit is contained in:
committed by
Matthew Barr
parent
a425bb9b7c
commit
9cf66b6ac9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -30,10 +30,11 @@
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "util/bitfield.h"
|
||||
#include "util/ue2_containers.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace std;
|
||||
using namespace ue2;
|
||||
|
||||
template<size_t N>
|
||||
@@ -393,9 +394,9 @@ TYPED_TEST(BitfieldTest, find_nth_sparse) {
|
||||
TYPED_TEST(BitfieldTest, unordered_set) {
|
||||
const size_t size = TypeParam::size();
|
||||
|
||||
// Exercise the hash_value free function by adding bitfields to an
|
||||
// Exercise the hash specialisation by adding bitfields to an
|
||||
// unordered_set.
|
||||
ue2::unordered_set<TypeParam> s;
|
||||
unordered_set<TypeParam> s;
|
||||
s.reserve(size);
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
|
@@ -29,9 +29,11 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "util/depth.h"
|
||||
#include "util/ue2_containers.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
using namespace std;
|
||||
using namespace ue2;
|
||||
|
||||
static UNUSED
|
||||
@@ -265,7 +267,7 @@ TEST(depth, u64a_operators) {
|
||||
}
|
||||
|
||||
TEST(depth, unordered_set) {
|
||||
ue2::unordered_set<depth> depths;
|
||||
unordered_set<depth> depths;
|
||||
|
||||
for (const auto &val : finite_values) {
|
||||
depths.emplace(val);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "util/ue2_containers.h"
|
||||
#include "util/flat_containers.h"
|
||||
#include "ue2common.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
@@ -403,6 +403,11 @@ TEST(flat_map, max_size) {
|
||||
ASSERT_LE(1ULL << 24, f.max_size());
|
||||
}
|
||||
|
||||
template<typename FlatMap>
|
||||
size_t hash_value(const FlatMap &f) {
|
||||
return std::hash<FlatMap>()(f);
|
||||
}
|
||||
|
||||
TEST(flat_map, hash_value) {
|
||||
const vector<pair<u32, u32>> input = {
|
||||
{0, 0}, {3, 1}, {76, 2}, {132, 3}, {77, 4}, {99999, 5}, {100, 6}};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -28,7 +28,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "util/ue2_containers.h"
|
||||
#include "util/flat_containers.h"
|
||||
#include "ue2common.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
@@ -393,6 +393,11 @@ TEST(flat_set, max_size) {
|
||||
ASSERT_LE(1ULL << 24, f.max_size());
|
||||
}
|
||||
|
||||
template<typename FlatSet>
|
||||
size_t hash_value(const FlatSet &f) {
|
||||
return std::hash<FlatSet>()(f);
|
||||
}
|
||||
|
||||
TEST(flat_set, hash_value) {
|
||||
const vector<u32> input = {0, 15, 3, 1, 20, 32768,
|
||||
24000000, 17, 100, 101, 104, 99999};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -79,8 +79,8 @@ TEST(NFAGraph, split1) {
|
||||
|
||||
NFAVertex pivot = c;
|
||||
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
|
||||
splitGraph(src, pivot, &lhs, &lhs_map, &rhs, &rhs_map);
|
||||
|
||||
@@ -130,8 +130,8 @@ TEST(NFAGraph, split2) {
|
||||
|
||||
NFAVertex pivot = c;
|
||||
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
|
||||
splitGraph(src, pivot, &lhs, &lhs_map, &rhs, &rhs_map);
|
||||
|
||||
@@ -203,8 +203,8 @@ TEST(NFAGraph, split3) {
|
||||
pivots.push_back(d);
|
||||
pivots.push_back(g);
|
||||
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
|
||||
splitGraph(src, pivots, &lhs, &lhs_map, &rhs, &rhs_map);
|
||||
|
||||
@@ -280,8 +280,8 @@ TEST(NFAGraph, split4) {
|
||||
pivots.push_back(d);
|
||||
pivots.push_back(g);
|
||||
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
ue2::unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> lhs_map;
|
||||
unordered_map<NFAVertex, NFAVertex> rhs_map;
|
||||
|
||||
splitGraph(src, pivots, &lhs, &lhs_map, &rhs, &rhs_map);
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015-2016, Intel Corporation
|
||||
* Copyright (c) 2015-2017, Intel Corporation
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
@@ -42,7 +42,11 @@
|
||||
#include "smallwrite/smallwrite_build.h"
|
||||
#include "som/slot_manager.h"
|
||||
|
||||
using std::vector;
|
||||
#include <memory>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace ue2;
|
||||
|
||||
static
|
||||
@@ -78,7 +82,7 @@ RoseVertex addVertex(RoseBuildImpl &build, RoseVertex parent, u32 lit_id) {
|
||||
|
||||
static
|
||||
size_t numUniqueSuffixGraphs(const RoseGraph &g) {
|
||||
ue2::unordered_set<const NGHolder *> seen;
|
||||
unordered_set<const NGHolder *> seen;
|
||||
|
||||
for (const auto &v : vertices_range(g)) {
|
||||
if (g[v].suffix) {
|
||||
|
Reference in New Issue
Block a user