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:
Justin Viiret
2017-07-14 14:59:52 +10:00
committed by Matthew Barr
parent a425bb9b7c
commit 9cf66b6ac9
123 changed files with 1048 additions and 772 deletions

View File

@@ -40,6 +40,7 @@
#include "nfagraph/ng_som_util.h"
#include "nfagraph/ng_region.h"
#include "util/charreach.h"
#include "util/hash.h"
#include "util/make_unique.h"
#include "util/dump_charclass.h"
#include "util/verify_types.h"
@@ -48,8 +49,6 @@
#include <deque>
#include <utility>
#include <boost/functional/hash/hash.hpp>
using namespace std;
namespace ue2 {
@@ -67,13 +66,8 @@ SlotCacheEntry::SlotCacheEntry(const NGHolder &prefix_in,
size_t SlotEntryHasher::operator()(const SlotCacheEntry &e) const {
assert(e.prefix);
using boost::hash_combine;
size_t v = 0;
hash_combine(v, hash_holder(*e.prefix));
hash_combine(v, e.parent_slot);
hash_combine(v, e.is_reset);
hash_combine(v, e.escapes.hash());
size_t v = hash_all(hash_holder(*e.prefix), e.parent_slot,
e.is_reset, e.escapes);
DEBUG_PRINTF("%zu vertices, parent_slot=%u, escapes=%s, is_reset=%d "
"hashes to %zx\n", num_vertices(*e.prefix), e.parent_slot,
@@ -143,7 +137,7 @@ u32 SomSlotManager::getSomSlot(const NGHolder &prefix,
u32 SomSlotManager::getInitialResetSomSlot(const NGHolder &prefix,
const NGHolder &g,
const ue2::unordered_map<NFAVertex, u32> &region_map,
const unordered_map<NFAVertex, u32> &region_map,
u32 last_sent_region, bool *prefix_already_implemented) {
DEBUG_PRINTF("getting initial reset; last sent region %u\n",
last_sent_region);
@@ -171,9 +165,9 @@ u32 SomSlotManager::getInitialResetSomSlot(const NGHolder &prefix,
// Clone a copy of g (and its region map) that we will be able to store
// later on.
shared_ptr<NGHolder> gg = make_shared<NGHolder>();
ue2::unordered_map<NFAVertex, NFAVertex> orig_to_copy;
unordered_map<NFAVertex, NFAVertex> orig_to_copy;
cloneHolder(*gg, g, &orig_to_copy);
ue2::unordered_map<NFAVertex, u32> gg_region_map;
unordered_map<NFAVertex, u32> gg_region_map;
for (const auto &m : region_map) {
assert(contains(region_map, m.first));
gg_region_map.emplace(orig_to_copy.at(m.first), m.second);

View File

@@ -38,10 +38,10 @@
#include "nfagraph/ng_holder.h"
#include "util/bytecode_ptr.h"
#include "util/noncopyable.h"
#include "util/ue2_containers.h"
#include <deque>
#include <memory>
#include <unordered_map>
struct NFA;
@@ -69,7 +69,7 @@ public:
/** prefix must be acting as a resetting sentinel and should be a dag (if
* not how are we establish som?) */
u32 getInitialResetSomSlot(const NGHolder &prefix, const NGHolder &g,
const ue2::unordered_map<NFAVertex, u32> &region_map,
const std::unordered_map<NFAVertex, u32> &region_map,
u32 last_sent_region,
bool *prefix_already_implemented);

View File

@@ -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:
@@ -32,10 +32,11 @@
#include "nfagraph/ng.h"
#include "nfagraph/ng_is_equal.h"
#include "util/charreach.h"
#include "util/ue2_containers.h"
#include "ue2common.h"
#include <memory>
#include <unordered_map>
#include <unordered_set>
#include <vector>
namespace ue2 {
@@ -43,14 +44,14 @@ namespace ue2 {
struct InitialResetEntry {
InitialResetEntry(std::shared_ptr<const NGHolder> sent_in,
std::shared_ptr<const NGHolder> body_in,
const ue2::unordered_map<NFAVertex, u32> &body_regions_in,
const std::unordered_map<NFAVertex, u32> &body_regions_in,
u32 sent_region_in, u32 first_bad_region_in)
: sent(sent_in), body(body_in), body_regions(body_regions_in),
sent_region(sent_region_in), first_bad_region(first_bad_region_in) {}
std::shared_ptr<const NGHolder> sent;
std::shared_ptr<const NGHolder> body;
ue2::unordered_map<NFAVertex, u32> body_regions;
std::unordered_map<NFAVertex, u32> body_regions;
u32 sent_region;
u32 first_bad_region; /* ~0U if it must cover the whole g */
};
@@ -85,7 +86,7 @@ struct SlotEntryEqual {
};
struct SlotCache {
typedef ue2::unordered_set<SlotCacheEntry, SlotEntryHasher,
typedef std::unordered_set<SlotCacheEntry, SlotEntryHasher,
SlotEntryEqual> CacheStore;
void insert(const NGHolder &prefix, const CharReach &escapes,
@@ -96,8 +97,8 @@ struct SlotCache {
CacheStore store;
ue2::unordered_set<std::shared_ptr<const NGHolder>, NGHolderHasher,
NGHolderEqual> initial_prefixes;
std::unordered_set<std::shared_ptr<const NGHolder>, NGHolderHasher,
NGHolderEqual> initial_prefixes;
std::vector<InitialResetInfo> initial_resets;
};