From 9cf66b6ac9cdd524d82d1aa68df4d2f1c28dae98 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Fri, 14 Jul 2017 14:59:52 +1000 Subject: [PATCH] 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 and ue2_unordered_map 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. --- CMakeLists.txt | 3 +- src/fdr/fdr_compile.cpp | 9 +- src/fdr/fdr_engine_description.h | 1 - src/fdr/teddy_compile.cpp | 1 + src/nfa/accel_dfa_build_strat.cpp | 3 +- src/nfa/accel_dump.cpp | 2 + src/nfa/accelcompile.h | 2 +- src/nfa/castlecompile.cpp | 4 +- src/nfa/castlecompile.h | 7 +- src/nfa/dfa_min.cpp | 2 +- src/nfa/goughcompile.cpp | 2 +- src/nfa/goughcompile.h | 2 +- src/nfa/goughcompile_internal.h | 2 +- src/nfa/goughcompile_reg.cpp | 6 +- src/nfa/limex_compile.cpp | 78 ++++----- src/nfa/limex_compile.h | 15 +- src/nfa/mcclellancompile.cpp | 2 +- src/nfa/mcclellancompile.h | 1 - src/nfa/mcclellancompile_util.cpp | 13 +- src/nfa/mcsheng_compile.cpp | 10 +- src/nfa/rdfa.h | 4 +- src/nfa/rdfa_merge.cpp | 5 +- src/nfa/shengcompile.h | 5 +- src/nfa/shufticompile.cpp | 4 +- src/nfa/shufticompile.h | 4 +- src/nfa/trufflecompile.cpp | 7 +- src/nfagraph/ng.h | 1 - src/nfagraph/ng_calc_components.cpp | 6 +- src/nfagraph/ng_cyclic_redundancy.cpp | 2 +- src/nfagraph/ng_dominators.cpp | 1 - src/nfagraph/ng_dominators.h | 11 +- src/nfagraph/ng_dump.cpp | 8 +- src/nfagraph/ng_dump.h | 7 +- src/nfagraph/ng_edge_redundancy.cpp | 2 +- src/nfagraph/ng_equivalence.cpp | 18 +-- src/nfagraph/ng_execute.h | 4 +- src/nfagraph/ng_haig.cpp | 7 +- src/nfagraph/ng_holder.h | 4 +- src/nfagraph/ng_is_equal.cpp | 14 +- src/nfagraph/ng_limex.cpp | 20 +-- src/nfagraph/ng_limex_accel.h | 2 +- src/nfagraph/ng_literal_analysis.cpp | 2 +- src/nfagraph/ng_literal_component.cpp | 4 +- src/nfagraph/ng_mcclellan.cpp | 5 +- src/nfagraph/ng_mcclellan_internal.h | 4 +- src/nfagraph/ng_misc_opt.cpp | 2 +- src/nfagraph/ng_prefilter.cpp | 11 +- src/nfagraph/ng_prune.cpp | 2 +- src/nfagraph/ng_redundancy.cpp | 9 +- src/nfagraph/ng_region.cpp | 2 +- src/nfagraph/ng_region.h | 20 +-- src/nfagraph/ng_region_redundancy.cpp | 10 +- src/nfagraph/ng_repeat.cpp | 130 +++++++-------- src/nfagraph/ng_repeat.h | 6 +- src/nfagraph/ng_restructuring.cpp | 6 +- src/nfagraph/ng_restructuring.h | 12 +- src/nfagraph/ng_revacc.cpp | 4 +- src/nfagraph/ng_som.cpp | 67 ++++---- src/nfagraph/ng_som_util.cpp | 12 +- src/nfagraph/ng_som_util.h | 8 +- src/nfagraph/ng_split.cpp | 28 ++-- src/nfagraph/ng_split.h | 20 +-- src/nfagraph/ng_squash.cpp | 19 ++- src/nfagraph/ng_squash.h | 7 +- src/nfagraph/ng_undirected.h | 8 +- src/nfagraph/ng_util.cpp | 17 +- src/nfagraph/ng_util.h | 19 +-- src/nfagraph/ng_violet.cpp | 12 +- src/parser/Parser.rl | 2 +- src/parser/buildstate.cpp | 8 +- src/parser/check_refs.cpp | 4 +- src/parser/check_refs.h | 16 +- src/rose/rose_build.h | 12 +- src/rose/rose_build_add.cpp | 2 +- src/rose/rose_build_anchored.cpp | 22 ++- src/rose/rose_build_bytecode.cpp | 22 +-- src/rose/rose_build_castle.cpp | 9 +- src/rose/rose_build_compile.cpp | 4 +- src/rose/rose_build_convert.cpp | 5 +- src/rose/rose_build_engine_blob.h | 14 +- src/rose/rose_build_exclusive.cpp | 26 +-- src/rose/rose_build_groups.h | 7 +- src/rose/rose_build_impl.h | 51 +++--- src/rose/rose_build_infix.cpp | 18 ++- src/rose/rose_build_instructions.h | 149 +++++++++--------- src/rose/rose_build_lookaround.cpp | 10 +- src/rose/rose_build_lookaround.h | 20 ++- src/rose/rose_build_merge.cpp | 28 ++-- src/rose/rose_build_misc.cpp | 28 +--- src/rose/rose_build_program.cpp | 11 +- src/rose/rose_build_program.h | 20 +-- src/rose/rose_build_role_aliasing.cpp | 24 +-- src/rose/rose_graph.h | 2 +- src/rose/rose_in_graph.h | 2 +- src/rose/rose_in_util.cpp | 3 +- src/som/slot_manager.cpp | 18 +-- src/som/slot_manager.h | 4 +- src/som/slot_manager_internal.h | 15 +- src/util/accel_scheme.h | 6 +- src/util/bitfield.h | 23 +-- src/util/charreach.h | 19 ++- src/util/clique.cpp | 3 +- src/util/depth.h | 26 ++- .../{ue2_containers.h => flat_containers.h} | 42 ++--- src/util/graph.h | 10 +- src/util/hash.h | 140 ++++++++++++++-- src/util/hash_dynamic_bitset.h | 5 +- src/util/multibit_build.h | 14 +- src/util/partitioned_set.h | 2 +- src/util/report.h | 22 ++- src/util/report_manager.h | 10 +- src/util/ue2_graph.h | 41 +++-- src/util/ue2string.cpp | 7 +- src/util/ue2string.h | 26 ++- src/util/unordered.h | 53 +++++++ unit/internal/bitfield.cpp | 9 +- unit/internal/depth.cpp | 6 +- unit/internal/flat_map.cpp | 9 +- unit/internal/flat_set.cpp | 9 +- unit/internal/nfagraph_util.cpp | 18 +-- unit/internal/rose_build_merge.cpp | 10 +- util/ng_corpus_generator.cpp | 4 +- util/ng_find_matches.cpp | 3 +- 123 files changed, 1048 insertions(+), 772 deletions(-) rename src/util/{ue2_containers.h => flat_containers.h} (96%) create mode 100644 src/util/unordered.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c51d6133..9aa30819 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -997,6 +997,7 @@ SET (hs_SRCS src/util/dump_mask.h src/util/fatbit_build.cpp src/util/fatbit_build.h + src/util/flat_containers.h src/util/graph.h src/util/graph_range.h src/util/graph_small_color_map.h @@ -1019,7 +1020,6 @@ SET (hs_SRCS src/util/small_vector.h src/util/target_info.cpp src/util/target_info.h - src/util/ue2_containers.h src/util/ue2_graph.h src/util/ue2string.cpp src/util/ue2string.h @@ -1027,6 +1027,7 @@ SET (hs_SRCS src/util/unicode_def.h src/util/unicode_set.h src/util/uniform_ops.h + src/util/unordered.h src/util/verify_types.h ) diff --git a/src/fdr/fdr_compile.cpp b/src/fdr/fdr_compile.cpp index dc91010e..210729a7 100644 --- a/src/fdr/fdr_compile.cpp +++ b/src/fdr/fdr_compile.cpp @@ -48,7 +48,6 @@ #include "util/math.h" #include "util/noncopyable.h" #include "util/target_info.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" #include "util/verify_types.h" @@ -64,6 +63,8 @@ #include #include #include +#include +#include #include #include @@ -459,7 +460,7 @@ bool getMultiEntriesAtPosition(const FDREngineDescription &eng, const vector &vl, const vector &lits, SuffixPositionInString pos, - std::map > &m2) { + map> &m2) { assert(eng.bits < 32); u32 distance = 0; @@ -530,7 +531,7 @@ void FDRCompiler::setupTab() { SuffixPositionInString pLimit = eng.getBucketWidth(b); for (SuffixPositionInString pos = 0; pos < pLimit; pos++) { u32 bit = eng.getSchemeBit(b, pos); - map> m2; + map> m2; bool done = getMultiEntriesAtPosition(eng, vl, lits, pos, m2); if (done) { clearbit(&defaultMask[0], bit); @@ -538,7 +539,7 @@ void FDRCompiler::setupTab() { } for (const auto &elem : m2) { u32 dc = elem.first; - const ue2::unordered_set &mskSet = elem.second; + const unordered_set &mskSet = elem.second; u32 v = ~dc; do { u32 b2 = v & dc; diff --git a/src/fdr/fdr_engine_description.h b/src/fdr/fdr_engine_description.h index 09c5ce86..1c464fe3 100644 --- a/src/fdr/fdr_engine_description.h +++ b/src/fdr/fdr_engine_description.h @@ -30,7 +30,6 @@ #define FDR_ENGINE_DESCRIPTION_H #include "engine_description.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/fdr/teddy_compile.cpp b/src/fdr/teddy_compile.cpp index bb02f759..98736134 100644 --- a/src/fdr/teddy_compile.cpp +++ b/src/fdr/teddy_compile.cpp @@ -49,6 +49,7 @@ #include "util/make_unique.h" #include "util/noncopyable.h" #include "util/popcount.h" +#include "util/small_vector.h" #include "util/target_info.h" #include "util/verify_types.h" diff --git a/src/nfa/accel_dfa_build_strat.cpp b/src/nfa/accel_dfa_build_strat.cpp index 7c56ba72..928e078e 100644 --- a/src/nfa/accel_dfa_build_strat.cpp +++ b/src/nfa/accel_dfa_build_strat.cpp @@ -41,6 +41,7 @@ #include "util/verify_types.h" #include +#include #include #define PATHS_LIMIT 500 @@ -254,7 +255,7 @@ dstate_id_t get_sds_or_proxy(const raw_dfa &raw) { u16 top_remap = raw.alpha_remap[TOP]; - ue2::unordered_set seen; + std::unordered_set seen; while (true) { seen.insert(s); DEBUG_PRINTF("basis %hu\n", s); diff --git a/src/nfa/accel_dump.cpp b/src/nfa/accel_dump.cpp index 0d19fa8c..4c33b351 100644 --- a/src/nfa/accel_dump.cpp +++ b/src/nfa/accel_dump.cpp @@ -44,6 +44,8 @@ #include "util/simd_types.h" #include +#include +#include #include #ifndef DUMP_SUPPORT diff --git a/src/nfa/accelcompile.h b/src/nfa/accelcompile.h index 9bd4ff18..d0b3cdc7 100644 --- a/src/nfa/accelcompile.h +++ b/src/nfa/accelcompile.h @@ -31,7 +31,7 @@ #include "ue2common.h" #include "util/charreach.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" union AccelAux; diff --git a/src/nfa/castlecompile.cpp b/src/nfa/castlecompile.cpp index 40fbc18c..3505e08a 100644 --- a/src/nfa/castlecompile.cpp +++ b/src/nfa/castlecompile.cpp @@ -48,11 +48,11 @@ #include "util/compile_context.h" #include "util/container.h" #include "util/dump_charclass.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/make_unique.h" #include "util/multibit_build.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" #include "util/verify_types.h" #include "grey.h" @@ -153,7 +153,7 @@ static void getNeighborInfo(const CliqueGraph &g, vector &neighbor, const CliqueVertex &cv, const set &group) { u32 id = g[cv].stateId; - ue2::unordered_set neighborId; + unordered_set neighborId; // find neighbors for cv for (const auto &v : adjacent_vertices_range(cv, g)) { diff --git a/src/nfa/castlecompile.h b/src/nfa/castlecompile.h index 9f44692d..aa4ed354 100644 --- a/src/nfa/castlecompile.h +++ b/src/nfa/castlecompile.h @@ -39,11 +39,12 @@ #include "nfagraph/ng_repeat.h" #include "util/bytecode_ptr.h" #include "util/depth.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include #include #include +#include #include struct NFA; @@ -89,7 +90,7 @@ struct CastleProto { std::map repeats; /** \brief Mapping from report to associated tops. */ - ue2::unordered_map> report_map; + std::unordered_map> report_map; /** * \brief Next top id to use. Repeats may be removed without top remapping, @@ -155,7 +156,7 @@ bool is_equal(const CastleProto &c1, const CastleProto &c2); * of the reports in the given set. */ bool requiresDedupe(const CastleProto &proto, - const ue2::flat_set &reports); + const flat_set &reports); /** * \brief Build an NGHolder from a CastleProto. diff --git a/src/nfa/dfa_min.cpp b/src/nfa/dfa_min.cpp index c97ca5fb..1a07e8a7 100644 --- a/src/nfa/dfa_min.cpp +++ b/src/nfa/dfa_min.cpp @@ -63,9 +63,9 @@ #include "rdfa.h" #include "ue2common.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/noncopyable.h" #include "util/partitioned_set.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfa/goughcompile.cpp b/src/nfa/goughcompile.cpp index 58b05d3d..ba7f2718 100644 --- a/src/nfa/goughcompile.cpp +++ b/src/nfa/goughcompile.cpp @@ -37,11 +37,11 @@ #include "nfa_internal.h" #include "util/compile_context.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/make_unique.h" #include "util/order_check.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" #include "util/verify_types.h" #include "ue2common.h" diff --git a/src/nfa/goughcompile.h b/src/nfa/goughcompile.h index 72469f3c..00da1891 100644 --- a/src/nfa/goughcompile.h +++ b/src/nfa/goughcompile.h @@ -33,7 +33,7 @@ #include "nfa_kind.h" #include "ue2common.h" #include "util/bytecode_ptr.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/order_check.h" #include diff --git a/src/nfa/goughcompile_internal.h b/src/nfa/goughcompile_internal.h index a6ba0d1b..9de88c77 100644 --- a/src/nfa/goughcompile_internal.h +++ b/src/nfa/goughcompile_internal.h @@ -33,9 +33,9 @@ #include "mcclellancompile.h" #include "ue2common.h" #include "util/charreach.h" +#include "util/flat_containers.h" #include "util/noncopyable.h" #include "util/order_check.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfa/goughcompile_reg.cpp b/src/nfa/goughcompile_reg.cpp index a9370450..48e515b9 100644 --- a/src/nfa/goughcompile_reg.cpp +++ b/src/nfa/goughcompile_reg.cpp @@ -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,10 @@ #include "gough_internal.h" #include "grey.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/graph_range.h" #include "util/order_check.h" -#include "util/ue2_containers.h" #include "ue2common.h" @@ -235,7 +235,7 @@ void handle_pending_vertices(GoughSSAVar *def, const GoughGraph &g, if (contains(aux.containing_v, def)) { def_v = aux.containing_v.at(def); } - ue2::unordered_set done; + unordered_set done; while (!pending_vertex.empty()) { GoughVertex current = *pending_vertex.begin(); pending_vertex.erase(current); diff --git a/src/nfa/limex_compile.cpp b/src/nfa/limex_compile.cpp index 5e18b800..94d9961b 100644 --- a/src/nfa/limex_compile.cpp +++ b/src/nfa/limex_compile.cpp @@ -53,12 +53,13 @@ #include "util/charreach.h" #include "util/compile_context.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/graph_range.h" #include "util/graph_small_color_map.h" #include "util/order_check.h" +#include "util/unordered.h" #include "util/verify_types.h" -#include "util/ue2_containers.h" #include #include @@ -97,16 +98,16 @@ struct precalcAccel { }; struct limex_accel_info { - ue2::unordered_set accelerable; + unordered_set accelerable; map precalc; - ue2::unordered_map> friends; - ue2::unordered_map accel_map; + unordered_map> friends; + unordered_map accel_map; }; static map reindexByStateId(const map &in, const NGHolder &g, - const ue2::unordered_map &state_ids, + const unordered_map &state_ids, const u32 num_states) { map out; @@ -138,7 +139,7 @@ reindexByStateId(const map &in, const NGHolder &g, struct build_info { build_info(NGHolder &hi, - const ue2::unordered_map &states_in, + const unordered_map &states_in, const vector &ri, const map &rsmi, const map &smi, @@ -161,7 +162,7 @@ struct build_info { } NGHolder &h; - const ue2::unordered_map &state_ids; + const unordered_map &state_ids; const vector &repeats; // Squash maps; state sets are indexed by state_id. @@ -169,7 +170,7 @@ struct build_info { map squashMap; const map> &tops; - ue2::unordered_set tugs; + unordered_set tugs; map br_cyclic; const set &zombies; bool do_accel; @@ -479,7 +480,7 @@ bool allow_wide_accel(const vector &vv, const NGHolder &g, static void nfaFindAccelSchemes(const NGHolder &g, const map &br_cyclic, - ue2::unordered_map *out) { + unordered_map *out) { vector refined_cr = reduced_cr(g, br_cyclic); NFAVertex sds_or_proxy = get_sds_or_proxy(g); @@ -504,8 +505,8 @@ void nfaFindAccelSchemes(const NGHolder &g, } struct fas_visitor : public boost::default_bfs_visitor { - fas_visitor(const ue2::unordered_map &am_in, - ue2::unordered_map *out_in) + fas_visitor(const unordered_map &am_in, + unordered_map *out_in) : accel_map(am_in), out(out_in) {} void discover_vertex(NFAVertex v, const NGHolder &) { @@ -516,13 +517,13 @@ struct fas_visitor : public boost::default_bfs_visitor { throw this; /* done */ } } - const ue2::unordered_map &accel_map; - ue2::unordered_map *out; + const unordered_map &accel_map; + unordered_map *out; }; static void filterAccelStates(NGHolder &g, const map> &tops, - ue2::unordered_map *accel_map) { + unordered_map *accel_map) { /* We want the NFA_MAX_ACCEL_STATES best acceleration states, everything * else should be ditched. We use a simple BFS to choose accel states near * the start. */ @@ -542,7 +543,7 @@ void filterAccelStates(NGHolder &g, const map> &tops, tempEdges.push_back(e); // Remove edge later. } - ue2::unordered_map out; + unordered_map out; try { boost::breadth_first_search(g, g.start, @@ -982,16 +983,18 @@ u32 addSquashMask(const build_info &args, const NFAVertex &v, return idx; } +using ReportListCache = ue2_unordered_map, u32>; + static u32 addReports(const flat_set &r, vector &reports, - unordered_map, u32> &reportListCache) { + ReportListCache &reports_cache) { assert(!r.empty()); vector my_reports(begin(r), end(r)); my_reports.push_back(MO_INVALID_IDX); // sentinel - auto cache_it = reportListCache.find(my_reports); - if (cache_it != end(reportListCache)) { + auto cache_it = reports_cache.find(my_reports); + if (cache_it != end(reports_cache)) { u32 offset = cache_it->second; DEBUG_PRINTF("reusing cached report list at %u\n", offset); return offset; @@ -1007,13 +1010,12 @@ u32 addReports(const flat_set &r, vector &reports, u32 offset = verify_u32(reports.size()); insert(&reports, reports.end(), my_reports); - reportListCache.emplace(move(my_reports), offset); + reports_cache.emplace(move(my_reports), offset); return offset; } static -void buildAcceptsList(const build_info &args, - unordered_map, u32> &reports_cache, +void buildAcceptsList(const build_info &args, ReportListCache &reports_cache, vector &verts, vector &accepts, vector &reports, vector &squash) { if (verts.empty()) { @@ -1051,8 +1053,7 @@ void buildAcceptsList(const build_info &args, } static -void buildAccepts(const build_info &args, - unordered_map, u32> &reports_cache, +void buildAccepts(const build_info &args, ReportListCache &reports_cache, NFAStateSet &acceptMask, NFAStateSet &acceptEodMask, vector &accepts, vector &acceptsEod, vector &reports, vector &squash) { @@ -1119,7 +1120,7 @@ u32 uncompressedStateSize(u32 num_states) { static u32 compressedStateSize(const NGHolder &h, const NFAStateSet &maskedStates, - const ue2::unordered_map &state_ids) { + const unordered_map &state_ids) { // Shrink state requirement to enough to fit the compressed largest reach. vector allreach(N_CHARS, 0); @@ -1190,7 +1191,7 @@ bool hasSquashableInitDs(const build_info &args) { static bool hasInitDsStates(const NGHolder &h, - const ue2::unordered_map &state_ids) { + const unordered_map &state_ids) { if (state_ids.at(h.startDs) != NO_STATE) { return true; } @@ -1358,17 +1359,16 @@ struct ExceptionProto { }; static -u32 buildExceptionMap(const build_info &args, - unordered_map, u32> &reports_cache, - const ue2::unordered_set &exceptional, +u32 buildExceptionMap(const build_info &args, ReportListCache &reports_cache, + const unordered_set &exceptional, map> &exceptionMap, vector &reportList) { const NGHolder &h = args.h; const u32 num_states = args.num_states; u32 exceptionCount = 0; - ue2::unordered_map pos_trigger; - ue2::unordered_map tug_trigger; + unordered_map pos_trigger; + unordered_map tug_trigger; for (u32 i = 0; i < args.repeats.size(); i++) { const BoundedRepeatData &br = args.repeats[i]; @@ -1893,7 +1893,7 @@ struct Factory { static void findExceptionalTransitions(const build_info &args, - ue2::unordered_set &exceptional, + unordered_set &exceptional, u32 maxShift) { const NGHolder &h = args.h; @@ -2168,9 +2168,9 @@ struct Factory { // We track report lists that have already been written into the global // list in case we can reuse them. - unordered_map, u32> reports_cache; + ReportListCache reports_cache; - ue2::unordered_set exceptional; + unordered_set exceptional; u32 shiftCount = findBestNumOfVarShifts(args); assert(shiftCount); u32 maxShift = findMaxVarShift(args, shiftCount); @@ -2374,10 +2374,10 @@ MAKE_LIMEX_TRAITS(512) // Some sanity tests, called by an assertion in generate(). static UNUSED bool isSane(const NGHolder &h, const map> &tops, - const ue2::unordered_map &state_ids, + const unordered_map &state_ids, u32 num_states) { - ue2::unordered_set seen; - ue2::unordered_set top_starts; + unordered_set seen; + unordered_set top_starts; for (const auto &vv : tops | map_values) { insert(&top_starts, vv); } @@ -2424,7 +2424,7 @@ bool isSane(const NGHolder &h, const map> &tops, #endif // NDEBUG static -u32 max_state(const ue2::unordered_map &state_ids) { +u32 max_state(const unordered_map &state_ids) { u32 rv = 0; for (const auto &m : state_ids) { DEBUG_PRINTF("state %u\n", m.second); @@ -2437,7 +2437,7 @@ u32 max_state(const ue2::unordered_map &state_ids) { } bytecode_ptr generate(NGHolder &h, - const ue2::unordered_map &states, + const unordered_map &states, const vector &repeats, const map &reportSquashMap, const map &squashMap, @@ -2507,7 +2507,7 @@ bytecode_ptr generate(NGHolder &h, } u32 countAccelStates(NGHolder &h, - const ue2::unordered_map &states, + const unordered_map &states, const vector &repeats, const map &reportSquashMap, const map &squashMap, diff --git a/src/nfa/limex_compile.h b/src/nfa/limex_compile.h index a12ae9f6..3b819739 100644 --- a/src/nfa/limex_compile.h +++ b/src/nfa/limex_compile.h @@ -34,15 +34,16 @@ #ifndef LIMEX_COMPILE_H #define LIMEX_COMPILE_H -#include -#include -#include - #include "nfagraph/ng_holder.h" #include "nfagraph/ng_squash.h" // for NFAStateSet #include "ue2common.h" #include "util/bytecode_ptr.h" -#include "util/ue2_containers.h" + +#include +#include +#include +#include +#include struct NFA; @@ -69,7 +70,7 @@ struct CompileContext; * graph. */ bytecode_ptr generate(NGHolder &g, - const ue2::unordered_map &states, + const std::unordered_map &states, const std::vector &repeats, const std::map &reportSquashMap, const std::map &squashMap, @@ -87,7 +88,7 @@ bytecode_ptr generate(NGHolder &g, * implementable. */ u32 countAccelStates(NGHolder &h, - const ue2::unordered_map &states, + const std::unordered_map &states, const std::vector &repeats, const std::map &reportSquashMap, const std::map &squashMap, diff --git a/src/nfa/mcclellancompile.cpp b/src/nfa/mcclellancompile.cpp index 93746777..8f73d077 100644 --- a/src/nfa/mcclellancompile.cpp +++ b/src/nfa/mcclellancompile.cpp @@ -46,7 +46,7 @@ #include "util/make_unique.h" #include "util/order_check.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/unaligned.h" #include "util/verify_types.h" diff --git a/src/nfa/mcclellancompile.h b/src/nfa/mcclellancompile.h index baf72d9c..ce63fbbf 100644 --- a/src/nfa/mcclellancompile.h +++ b/src/nfa/mcclellancompile.h @@ -33,7 +33,6 @@ #include "rdfa.h" #include "ue2common.h" #include "util/bytecode_ptr.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfa/mcclellancompile_util.cpp b/src/nfa/mcclellancompile_util.cpp index 317c5889..977cf3d5 100644 --- a/src/nfa/mcclellancompile_util.cpp +++ b/src/nfa/mcclellancompile_util.cpp @@ -30,12 +30,11 @@ #include "rdfa.h" #include "util/container.h" -#include "util/ue2_containers.h" +#include "util/hash.h" #include "ue2common.h" #include - -#include +#include using namespace std; @@ -232,22 +231,18 @@ bool has_non_eod_accepts(const raw_dfa &rdfa) { } size_t hash_dfa_no_reports(const raw_dfa &rdfa) { - using boost::hash_combine; - using boost::hash_range; - size_t v = 0; hash_combine(v, rdfa.alpha_size); - hash_combine(v, hash_range(begin(rdfa.alpha_remap), end(rdfa.alpha_remap))); + hash_combine(v, rdfa.alpha_remap); for (const auto &ds : rdfa.states) { - hash_combine(v, hash_range(begin(ds.next), end(ds.next))); + hash_combine(v, ds.next); } return v; } size_t hash_dfa(const raw_dfa &rdfa) { - using boost::hash_combine; size_t v = 0; hash_combine(v, hash_dfa_no_reports(rdfa)); hash_combine(v, all_reports(rdfa)); diff --git a/src/nfa/mcsheng_compile.cpp b/src/nfa/mcsheng_compile.cpp index 2049fee0..728f03be 100644 --- a/src/nfa/mcsheng_compile.cpp +++ b/src/nfa/mcsheng_compile.cpp @@ -45,13 +45,14 @@ #include "util/compare.h" #include "util/compile_context.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/graph_range.h" #include "util/make_unique.h" #include "util/order_check.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" #include "util/unaligned.h" +#include "util/unordered.h" #include "util/verify_types.h" #include @@ -383,6 +384,8 @@ CharReach get_edge_reach(dstate_id_t u, dstate_id_t v, const dfa_info &info) { #define MAX_SHENG_STATES 16 #define MAX_SHENG_LEAKINESS 0.05 +using LeakinessCache = ue2_unordered_map, double>; + /** * Returns the proportion of strings of length 'depth' which will leave the * sheng region when starting at state 'u'. @@ -390,8 +393,7 @@ CharReach get_edge_reach(dstate_id_t u, dstate_id_t v, const dfa_info &info) { static double leakiness(const RdfaGraph &g, dfa_info &info, const flat_set &sheng_states, RdfaVertex u, - u32 depth, - unordered_map, double> &cache) { + u32 depth, LeakinessCache &cache) { double rv = 0; if (contains(cache, make_pair(u, depth))) { return cache[make_pair(u, depth)]; @@ -426,7 +428,7 @@ double leakiness(const RdfaGraph &g, dfa_info &info, static double leakiness(const RdfaGraph &g, dfa_info &info, const flat_set &sheng_states, RdfaVertex u) { - unordered_map, double> cache; + LeakinessCache cache; double rv = leakiness(g, info, sheng_states, u, 8, cache); return rv; } diff --git a/src/nfa/rdfa.h b/src/nfa/rdfa.h index fc60f177..0936fb15 100644 --- a/src/nfa/rdfa.h +++ b/src/nfa/rdfa.h @@ -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,7 +32,7 @@ #include "nfa_kind.h" #include "ue2common.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include #include diff --git a/src/nfa/rdfa_merge.cpp b/src/nfa/rdfa_merge.cpp index 0905dc08..2ad87123 100644 --- a/src/nfa/rdfa_merge.cpp +++ b/src/nfa/rdfa_merge.cpp @@ -36,9 +36,10 @@ #include "nfagraph/ng_mcclellan_internal.h" #include "util/container.h" #include "util/determinise.h" +#include "util/flat_containers.h" #include "util/make_unique.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" +#include "util/unordered.h" #include #include @@ -54,7 +55,7 @@ namespace { class Automaton_Merge { public: using StateSet = vector; - using StateMap = unordered_map; + using StateMap = ue2_unordered_map; Automaton_Merge(const raw_dfa *rdfa1, const raw_dfa *rdfa2, const ReportManager *rm_in, const Grey &grey_in) diff --git a/src/nfa/shengcompile.h b/src/nfa/shengcompile.h index 9885cd16..2fe1e356 100644 --- a/src/nfa/shengcompile.h +++ b/src/nfa/shengcompile.h @@ -33,7 +33,10 @@ #include "rdfa.h" #include "util/bytecode_ptr.h" #include "util/charreach.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" + +#include +#include struct NFA; diff --git a/src/nfa/shufticompile.cpp b/src/nfa/shufticompile.cpp index 12a94b7b..f712ef94 100644 --- a/src/nfa/shufticompile.cpp +++ b/src/nfa/shufticompile.cpp @@ -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: @@ -33,7 +33,7 @@ #include "ue2common.h" #include "util/charreach.h" #include "util/container.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include #include diff --git a/src/nfa/shufticompile.h b/src/nfa/shufticompile.h index a72904e0..59b9c38d 100644 --- a/src/nfa/shufticompile.h +++ b/src/nfa/shufticompile.h @@ -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: @@ -35,7 +35,7 @@ #include "ue2common.h" #include "util/charreach.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include diff --git a/src/nfa/trufflecompile.cpp b/src/nfa/trufflecompile.cpp index 9442d046..f19de0ee 100644 --- a/src/nfa/trufflecompile.cpp +++ b/src/nfa/trufflecompile.cpp @@ -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: @@ -32,12 +32,15 @@ * truffle is always able to represent an entire character class, providing a * backstop to other acceleration engines. */ + #include "trufflecompile.h" + #include "ue2common.h" #include "util/charreach.h" +#include "util/dump_mask.h" #include "util/simd_types.h" -#include "util/dump_mask.h" +#include using namespace std; diff --git a/src/nfagraph/ng.h b/src/nfagraph/ng.h index a5a5c235..a1304583 100644 --- a/src/nfagraph/ng.h +++ b/src/nfagraph/ng.h @@ -44,7 +44,6 @@ #include "util/graph.h" #include "util/noncopyable.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfagraph/ng_calc_components.cpp b/src/nfagraph/ng_calc_components.cpp index 7ac57dab..65574b50 100644 --- a/src/nfagraph/ng_calc_components.cpp +++ b/src/nfagraph/ng_calc_components.cpp @@ -310,11 +310,11 @@ void splitIntoComponents(unique_ptr g, return; } - ue2::unordered_map old2new; + unordered_map old2new; auto ug = createUnGraph(*g, true, true, old2new); // Construct reverse mapping. - ue2::unordered_map new2old; + unordered_map new2old; for (const auto &m : old2new) { new2old.emplace(m.second, m.first); } @@ -356,7 +356,7 @@ void splitIntoComponents(unique_ptr g, DEBUG_PRINTF("vertex %zu is in comp %u\n", (*g)[v].index, c); } - ue2::unordered_map v_map; // temp map for fillHolder + unordered_map v_map; // temp map for fillHolder for (auto &vv : verts) { // Shells are in every component. vv.insert(vv.end(), begin(head_shell), end(head_shell)); diff --git a/src/nfagraph/ng_cyclic_redundancy.cpp b/src/nfagraph/ng_cyclic_redundancy.cpp index 80980a66..c8d34687 100644 --- a/src/nfagraph/ng_cyclic_redundancy.cpp +++ b/src/nfagraph/ng_cyclic_redundancy.cpp @@ -62,9 +62,9 @@ #include "ng_prune.h" #include "ng_util.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/graph_small_color_map.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfagraph/ng_dominators.cpp b/src/nfagraph/ng_dominators.cpp index 50536b76..d6a064d1 100644 --- a/src/nfagraph/ng_dominators.cpp +++ b/src/nfagraph/ng_dominators.cpp @@ -36,7 +36,6 @@ #include "ue2common.h" #include "ng_holder.h" #include "ng_util.h" -#include "util/ue2_containers.h" #include // locally patched version #include diff --git a/src/nfagraph/ng_dominators.h b/src/nfagraph/ng_dominators.h index 81b7e037..f505b7e4 100644 --- a/src/nfagraph/ng_dominators.h +++ b/src/nfagraph/ng_dominators.h @@ -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: @@ -36,15 +36,14 @@ #define NG_DOMINATORS_H #include "ng_holder.h" -#include "util/ue2_containers.h" + +#include namespace ue2 { -class NGHolder; +std::unordered_map findDominators(const NGHolder &g); -ue2::unordered_map findDominators(const NGHolder &g); - -ue2::unordered_map findPostDominators(const NGHolder &g); +std::unordered_map findPostDominators(const NGHolder &g); } // namespace ue2 diff --git a/src/nfagraph/ng_dump.cpp b/src/nfagraph/ng_dump.cpp index 9624f762..8777a750 100644 --- a/src/nfagraph/ng_dump.cpp +++ b/src/nfagraph/ng_dump.cpp @@ -176,7 +176,7 @@ public: : g(g_in), rm(&rm_in) {} NFAWriter(const GraphT &g_in, - const ue2::unordered_map ®ion_map_in) + const unordered_map ®ion_map_in) : g(g_in), region_map(®ion_map_in) {} void operator()(ostream& os, const VertexT& v) const { @@ -254,7 +254,7 @@ public: private: const GraphT &g; const ReportManager *rm = nullptr; - const ue2::unordered_map *region_map = nullptr; + const unordered_map *region_map = nullptr; }; } @@ -278,7 +278,7 @@ void dumpGraphImpl(const char *name, const GraphT &g, const ReportManager &rm) { template void dumpGraphImpl(const char *name, const GraphT &g, - const ue2::unordered_map ®ion_map) { + const unordered_map ®ion_map) { typedef typename boost::graph_traits::vertex_descriptor VertexT; typedef typename boost::graph_traits::edge_descriptor EdgeT; ofstream os(name); @@ -332,7 +332,7 @@ void dumpHolderImpl(const NGHolder &h, unsigned int stageNumber, } void dumpHolderImpl(const NGHolder &h, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, unsigned int stageNumber, const char *stageName, const Grey &grey) { if (grey.dumpFlags & Grey::DUMP_INT_GRAPH) { diff --git a/src/nfagraph/ng_dump.h b/src/nfagraph/ng_dump.h index 077f07ce..3e12d1d2 100644 --- a/src/nfagraph/ng_dump.h +++ b/src/nfagraph/ng_dump.h @@ -36,7 +36,8 @@ #include "grey.h" #include "ng_holder.h" // for graph types #include "ue2common.h" -#include "util/ue2_containers.h" + +#include #ifdef DUMP_SUPPORT #include @@ -75,7 +76,7 @@ void dumpHolderImpl(const NGHolder &h, unsigned int stageNumber, // Variant that takes a region map as well. void dumpHolderImpl(const NGHolder &h, - const ue2::unordered_map ®ion_map, + const std::unordered_map ®ion_map, unsigned int stageNumber, const char *stageName, const Grey &grey); @@ -123,7 +124,7 @@ void dumpHolder(UNUSED const NGHolder &h, UNUSED unsigned int stageNumber, UNUSED static inline void dumpHolder(UNUSED const NGHolder &h, - UNUSED const ue2::unordered_map ®ion_map, + UNUSED const std::unordered_map ®ion_map, UNUSED unsigned int stageNumber, UNUSED const char *name, UNUSED const Grey &grey) { #ifdef DUMP_SUPPORT diff --git a/src/nfagraph/ng_edge_redundancy.cpp b/src/nfagraph/ng_edge_redundancy.cpp index 1578d2e4..b8354bd4 100644 --- a/src/nfagraph/ng_edge_redundancy.cpp +++ b/src/nfagraph/ng_edge_redundancy.cpp @@ -38,8 +38,8 @@ #include "parser/position.h" #include "util/compile_context.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfagraph/ng_equivalence.cpp b/src/nfagraph/ng_equivalence.cpp index 438e5ea8..a42a0ac7 100644 --- a/src/nfagraph/ng_equivalence.cpp +++ b/src/nfagraph/ng_equivalence.cpp @@ -37,9 +37,10 @@ #include "ng_holder.h" #include "ng_util.h" #include "util/compile_context.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" +#include "util/unordered.h" #include #include @@ -121,16 +122,9 @@ public: vertex_flags == b.vertex_flags && rs == b.rs; } - friend size_t hash_value(const ClassInfo &c) { - size_t val = 0; - boost::hash_combine(val, c.rs); - boost::hash_combine(val, c.vertex_flags); - boost::hash_combine(val, c.cr); - boost::hash_combine(val, c.adjacent_cr); - boost::hash_combine(val, c.node_type); - boost::hash_combine(val, c.depth.d1); - boost::hash_combine(val, c.depth.d2); - return val; + size_t hash() const { + return hash_all(rs, vertex_flags, cr, adjacent_cr, node_type, depth.d1, + depth.d2); } private: @@ -319,7 +313,7 @@ vector partitionGraph(vector> &infos, const size_t num_verts = infos.size(); vector classes; - unordered_map classinfomap; + ue2_unordered_map classinfomap; // assume we will have lots of classes, so we don't waste time resizing // these structures. diff --git a/src/nfagraph/ng_execute.h b/src/nfagraph/ng_execute.h index bdcfecfd..32f5520d 100644 --- a/src/nfagraph/ng_execute.h +++ b/src/nfagraph/ng_execute.h @@ -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: @@ -35,7 +35,7 @@ #define NG_EXECUTE_H #include "ng_holder.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include diff --git a/src/nfagraph/ng_haig.cpp b/src/nfagraph/ng_haig.cpp index 9582a1e8..992faf7c 100644 --- a/src/nfagraph/ng_haig.cpp +++ b/src/nfagraph/ng_haig.cpp @@ -40,11 +40,12 @@ #include "util/bitfield.h" #include "util/container.h" #include "util/determinise.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/graph_range.h" #include "util/hash_dynamic_bitset.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" +#include "util/unordered.h" #include #include @@ -258,7 +259,7 @@ public: struct Graph_Traits { using StateSet = bitfield; - using StateMap = ue2::unordered_map; + using StateMap = unordered_map; static StateSet init_states(UNUSED u32 num) { assert(num <= NFA_STATE_LIMIT); @@ -286,7 +287,7 @@ public: class Automaton_Haig_Merge { public: using StateSet = vector; - using StateMap = unordered_map; + using StateMap = ue2_unordered_map; explicit Automaton_Haig_Merge(const vector &in) : nfas(in.begin(), in.end()), dead(in.size()) { diff --git a/src/nfagraph/ng_holder.h b/src/nfagraph/ng_holder.h index fbb6ac52..f61c476a 100644 --- a/src/nfagraph/ng_holder.h +++ b/src/nfagraph/ng_holder.h @@ -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: @@ -40,7 +40,7 @@ #include "ue2common.h" #include "nfa/nfa_kind.h" #include "util/charreach.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/ue2_graph.h" namespace ue2 { diff --git a/src/nfagraph/ng_is_equal.cpp b/src/nfagraph/ng_is_equal.cpp index 2df79f50..35a09d0e 100644 --- a/src/nfagraph/ng_is_equal.cpp +++ b/src/nfagraph/ng_is_equal.cpp @@ -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: @@ -39,13 +39,9 @@ #include "ng_util.h" #include "ue2common.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" - -#include - -#include using namespace std; @@ -200,11 +196,11 @@ u64a hash_holder(const NGHolder &g) { size_t rv = 0; for (auto v : vertices_range(g)) { - boost::hash_combine(rv, g[v].index); - boost::hash_combine(rv, g[v].char_reach); + hash_combine(rv, g[v].index); + hash_combine(rv, g[v].char_reach); for (auto w : adjacent_vertices_range(v, g)) { - boost::hash_combine(rv, g[w].index); + hash_combine(rv, g[w].index); } } diff --git a/src/nfagraph/ng_limex.cpp b/src/nfagraph/ng_limex.cpp index 283bba22..1daec578 100644 --- a/src/nfagraph/ng_limex.cpp +++ b/src/nfagraph/ng_limex.cpp @@ -53,11 +53,13 @@ #include "util/container.h" #include "util/graph_range.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/verify_types.h" #include #include +#include +#include #include #include @@ -73,8 +75,8 @@ namespace ue2 { // Only used in assertions. static bool sanityCheckGraph(const NGHolder &g, - const ue2::unordered_map &state_ids) { - ue2::unordered_set seen_states; + const unordered_map &state_ids) { + unordered_set seen_states; for (auto v : vertices_range(g)) { // Non-specials should have non-empty reachability. @@ -468,7 +470,7 @@ void makeTopStates(NGHolder &g, map> &tops_out, static set findZombies(const NGHolder &h, const map &br_cyclic, - const ue2::unordered_map &state_ids, + const unordered_map &state_ids, const CompileContext &cc) { set zombies; if (!cc.grey.allowZombies) { @@ -516,7 +518,7 @@ set findZombies(const NGHolder &h, } static -void reverseStateOrdering(ue2::unordered_map &state_ids) { +void reverseStateOrdering(unordered_map &state_ids) { vector ordering; for (auto &e : state_ids) { if (e.second == NO_STATE) { @@ -569,7 +571,7 @@ prepareGraph(const NGHolder &h_in, const ReportManager *rm, const map &fixed_depth_tops, const map>> &triggers, bool impl_test_only, const CompileContext &cc, - ue2::unordered_map &state_ids, + unordered_map &state_ids, vector &repeats, map> &tops) { assert(is_triggered(h_in) || fixed_depth_tops.empty()); @@ -637,7 +639,7 @@ constructNFA(const NGHolder &h_in, const ReportManager *rm, assert(rm); } - ue2::unordered_map state_ids; + unordered_map state_ids; vector repeats; map> tops; unique_ptr h @@ -785,7 +787,7 @@ u32 isImplementableNFA(const NGHolder &g, const ReportManager *rm, * resultant NGHolder has <= NFA_MAX_STATES. If it does, we know we can * implement it as an NFA. */ - ue2::unordered_map state_ids; + unordered_map state_ids; vector repeats; map> tops; unique_ptr h @@ -832,7 +834,7 @@ u32 countAccelStates(const NGHolder &g, const ReportManager *rm, const map fixed_depth_tops; // empty const map>> triggers; // empty - ue2::unordered_map state_ids; + unordered_map state_ids; vector repeats; map> tops; unique_ptr h diff --git a/src/nfagraph/ng_limex_accel.h b/src/nfagraph/ng_limex_accel.h index f0c98db2..4c3d2b91 100644 --- a/src/nfagraph/ng_limex_accel.h +++ b/src/nfagraph/ng_limex_accel.h @@ -39,8 +39,8 @@ #include "nfa/accelcompile.h" #include "util/accel_scheme.h" #include "util/charreach.h" +#include "util/flat_containers.h" #include "util/order_check.h" -#include "util/ue2_containers.h" #include #include diff --git a/src/nfagraph/ng_literal_analysis.cpp b/src/nfagraph/ng_literal_analysis.cpp index 87c4e79e..ea0def02 100644 --- a/src/nfagraph/ng_literal_analysis.cpp +++ b/src/nfagraph/ng_literal_analysis.cpp @@ -811,7 +811,7 @@ bool splitOffLeadingLiteral(const NGHolder &g, ue2_literal *lit_out, } assert(u != g.startDs); - ue2::unordered_map rhs_map; + unordered_map rhs_map; vector pivots = make_vector_from(adjacent_vertices(u, g)); splitRHS(g, pivots, rhs, &rhs_map); diff --git a/src/nfagraph/ng_literal_component.cpp b/src/nfagraph/ng_literal_component.cpp index de05e490..4d3965df 100644 --- a/src/nfagraph/ng_literal_component.cpp +++ b/src/nfagraph/ng_literal_component.cpp @@ -45,6 +45,8 @@ #include "util/graph_range.h" #include "util/ue2string.h" +#include + using namespace std; namespace ue2 { @@ -196,7 +198,7 @@ bool splitOffLiterals(NG &ng, NGHolder &g) { bool changed = false; set dead; - ue2::unordered_set unanchored; // for faster lookup. + unordered_set unanchored; // for faster lookup. insert(&unanchored, adjacent_vertices(g.startDs, g)); // Anchored literals. diff --git a/src/nfagraph/ng_mcclellan.cpp b/src/nfagraph/ng_mcclellan.cpp index ec8ae223..091b89b8 100644 --- a/src/nfagraph/ng_mcclellan.cpp +++ b/src/nfagraph/ng_mcclellan.cpp @@ -41,17 +41,18 @@ #include "ue2common.h" #include "util/bitfield.h" #include "util/determinise.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/hash.h" #include "util/hash_dynamic_bitset.h" #include "util/make_unique.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" #include #include #include #include +#include #include #include @@ -483,7 +484,7 @@ public: struct Graph_Traits { using StateSet = bitfield; - using StateMap = ue2::unordered_map; + using StateMap = unordered_map; static StateSet init_states(UNUSED u32 num) { assert(num <= NFA_STATE_LIMIT); diff --git a/src/nfagraph/ng_mcclellan_internal.h b/src/nfagraph/ng_mcclellan_internal.h index b78dac3b..f069d733 100644 --- a/src/nfagraph/ng_mcclellan_internal.h +++ b/src/nfagraph/ng_mcclellan_internal.h @@ -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: @@ -38,7 +38,7 @@ #include "nfagraph/ng_holder.h" #include "util/charreach.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include diff --git a/src/nfagraph/ng_misc_opt.cpp b/src/nfagraph/ng_misc_opt.cpp index c8dfcbab..8aaaf99f 100644 --- a/src/nfagraph/ng_misc_opt.cpp +++ b/src/nfagraph/ng_misc_opt.cpp @@ -70,7 +70,7 @@ #include "util/container.h" #include "util/graph_range.h" #include "util/graph_small_color_map.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "ue2common.h" #include diff --git a/src/nfagraph/ng_prefilter.cpp b/src/nfagraph/ng_prefilter.cpp index 64d4cf2f..04611872 100644 --- a/src/nfagraph/ng_prefilter.cpp +++ b/src/nfagraph/ng_prefilter.cpp @@ -55,10 +55,11 @@ #include "util/compile_context.h" #include "util/container.h" #include "util/dump_charclass.h" -#include "util/ue2_containers.h" #include "util/graph_range.h" #include +#include +#include #include @@ -127,10 +128,10 @@ struct RegionInfoQueueComp { static void findWidths(const NGHolder &g, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, RegionInfo &ri) { NGHolder rg; - ue2::unordered_map mapping; + unordered_map mapping; fillHolder(&rg, g, ri.vertices, &mapping); // Wire our entries to start and our exits to accept. @@ -155,7 +156,7 @@ void findWidths(const NGHolder &g, // acc can be either h.accept or h.acceptEod. static void markBoundaryRegions(const NGHolder &h, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, map ®ions, NFAVertex acc) { for (auto v : inv_adjacent_vertices_range(acc, h)) { if (is_special(v, h)) { @@ -174,7 +175,7 @@ void markBoundaryRegions(const NGHolder &h, static map findRegionInfo(const NGHolder &h, - const ue2::unordered_map ®ion_map) { + const unordered_map ®ion_map) { map regions; for (auto v : vertices_range(h)) { if (is_special(v, h)) { diff --git a/src/nfagraph/ng_prune.cpp b/src/nfagraph/ng_prune.cpp index 72d017ae..adda7031 100644 --- a/src/nfagraph/ng_prune.cpp +++ b/src/nfagraph/ng_prune.cpp @@ -223,7 +223,7 @@ void pruneHighlanderAccepts(NGHolder &g, const ReportManager &rm) { static bool isDominatedByReporter(const NGHolder &g, - const ue2::unordered_map &dom, + const unordered_map &dom, NFAVertex v, ReportID report_id) { for (auto it = dom.find(v); it != end(dom); it = dom.find(v)) { NFAVertex u = it->second; diff --git a/src/nfagraph/ng_redundancy.cpp b/src/nfagraph/ng_redundancy.cpp index 76bc93da..06b9daee 100644 --- a/src/nfagraph/ng_redundancy.cpp +++ b/src/nfagraph/ng_redundancy.cpp @@ -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: @@ -78,8 +78,8 @@ #include "ng_util.h" #include "ue2common.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" #include #include @@ -747,7 +747,7 @@ u32 findCyclic(const NGHolder &g, vector &cyclic) { static void findCyclicDom(NGHolder &g, vector &cyclic, set &dead, som_type som) { - ue2::unordered_map dominators = findDominators(g); + auto dominators = findDominators(g); for (auto v : vertices_range(g)) { if (is_special(v, g)) { @@ -791,8 +791,7 @@ void findCyclicDom(NGHolder &g, vector &cyclic, static void findCyclicPostDom(NGHolder &g, vector &cyclic, set &dead) { - ue2::unordered_map postdominators = - findPostDominators(g); + auto postdominators = findPostDominators(g); for (auto v : vertices_range(g)) { if (is_special(v, g)) { diff --git a/src/nfagraph/ng_region.cpp b/src/nfagraph/ng_region.cpp index 6463a281..2675be64 100644 --- a/src/nfagraph/ng_region.cpp +++ b/src/nfagraph/ng_region.cpp @@ -56,7 +56,7 @@ #include "ng_util.h" #include "ue2common.h" #include "util/container.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/graph_small_color_map.h" diff --git a/src/nfagraph/ng_region.h b/src/nfagraph/ng_region.h index a56933dc..a4708a58 100644 --- a/src/nfagraph/ng_region.h +++ b/src/nfagraph/ng_region.h @@ -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: @@ -36,19 +36,19 @@ #include "ng_holder.h" #include "util/container.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" +#include #include namespace ue2 { /** \brief Assign a region ID to every vertex in the graph. */ -ue2::unordered_map assignRegions(const NGHolder &g); +std::unordered_map assignRegions(const NGHolder &g); /** \brief True if vertices \p a and \p b are in the same region. */ template bool inSameRegion(const Graph &g, NFAVertex a, NFAVertex b, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { assert(contains(region_map, a) && contains(region_map, b)); return region_map.at(a) == region_map.at(b) && @@ -58,7 +58,7 @@ bool inSameRegion(const Graph &g, NFAVertex a, NFAVertex b, /** \brief True if vertex \p b is in a later region than vertex \p a. */ template bool inLaterRegion(const Graph &g, NFAVertex a, NFAVertex b, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { assert(contains(region_map, a) && contains(region_map, b)); u32 aa = g[a].index; @@ -85,7 +85,7 @@ bool inLaterRegion(const Graph &g, NFAVertex a, NFAVertex b, /** \brief True if vertex \p b is in an earlier region than vertex \p a. */ template bool inEarlierRegion(const Graph &g, NFAVertex a, NFAVertex b, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { assert(contains(region_map, a) && contains(region_map, b)); u32 aa = g[a].index; @@ -112,7 +112,7 @@ bool inEarlierRegion(const Graph &g, NFAVertex a, NFAVertex b, /** \brief True if vertex \p v is an entry vertex for its region. */ template bool isRegionEntry(const Graph &g, NFAVertex v, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { // Note that some graph types do not have inv_adjacent_vertices, so we must // use in_edges here. for (const auto &e : in_edges_range(v, g)) { @@ -127,7 +127,7 @@ bool isRegionEntry(const Graph &g, NFAVertex v, /** \brief True if vertex \p v is an exit vertex for its region. */ template bool isRegionExit(const Graph &g, NFAVertex v, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { for (auto w : adjacent_vertices_range(v, g)) { if (!inSameRegion(g, v, w, region_map)) { return true; @@ -140,7 +140,7 @@ bool isRegionExit(const Graph &g, NFAVertex v, /** \brief True if vertex \p v is in a region all on its own. */ template bool isSingletonRegion(const Graph &g, NFAVertex v, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { for (const auto &e : in_edges_range(v, g)) { auto u = source(e, g); if (u != v && inSameRegion(g, v, u, region_map)) { @@ -178,7 +178,7 @@ bool isSingletonRegion(const Graph &g, NFAVertex v, */ template bool isOptionalRegion(const Graph &g, NFAVertex v, - const ue2::unordered_map ®ion_map) { + const std::unordered_map ®ion_map) { assert(isRegionEntry(g, v, region_map)); DEBUG_PRINTF("check if r%u is optional (inspecting v%zu)\n", diff --git a/src/nfagraph/ng_region_redundancy.cpp b/src/nfagraph/ng_region_redundancy.cpp index 264e4312..1126d4d6 100644 --- a/src/nfagraph/ng_region_redundancy.cpp +++ b/src/nfagraph/ng_region_redundancy.cpp @@ -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: @@ -60,7 +60,7 @@ struct RegionInfo { static bool regionHasUnexpectedAccept(const NGHolder &g, const u32 region, const flat_set &expected_reports, - const ue2::unordered_map ®ion_map) { + const unordered_map ®ion_map) { /* TODO: only check vertices connected to accept/acceptEOD */ for (auto v : vertices_range(g)) { if (region != region_map.at(v)) { @@ -84,7 +84,7 @@ bool regionHasUnexpectedAccept(const NGHolder &g, const u32 region, static void processCyclicStateForward(NGHolder &h, NFAVertex cyc, const map &info, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, set &deadRegions) { u32 region = region_map.at(cyc); CharReach cr = h[cyc].char_reach; @@ -130,7 +130,7 @@ void processCyclicStateForward(NGHolder &h, NFAVertex cyc, static void processCyclicStateReverse(NGHolder &h, NFAVertex cyc, const map &info, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, set &deadRegions) { u32 region = region_map.at(cyc); CharReach cr = h[cyc].char_reach; @@ -179,7 +179,7 @@ void processCyclicStateReverse(NGHolder &h, NFAVertex cyc, static map buildRegionInfoMap(const NGHolder &g, - const ue2::unordered_map ®ion_map) { + const unordered_map ®ion_map) { map info; for (auto v : vertices_range(g)) { diff --git a/src/nfagraph/ng_repeat.cpp b/src/nfagraph/ng_repeat.cpp index 4487376a..da42b36d 100644 --- a/src/nfagraph/ng_repeat.cpp +++ b/src/nfagraph/ng_repeat.cpp @@ -49,10 +49,13 @@ #include "util/graph_range.h" #include "util/graph_small_color_map.h" #include "util/report_manager.h" +#include "util/unordered.h" #include #include #include +#include +#include #include #include @@ -64,6 +67,7 @@ using namespace std; using boost::depth_first_search; using boost::depth_first_visit; +using boost::make_assoc_property_map; namespace ue2 { @@ -118,7 +122,7 @@ struct ReachSubgraph { static void findInitDepths(const NGHolder &g, - ue2::unordered_map &depths) { + unordered_map &depths) { auto d = calcDepths(g); for (auto v : vertices_range(g)) { @@ -133,12 +137,12 @@ vector buildTopoOrder(const RepeatGraph &g) { /* Note: RepeatGraph is a filtered version of NGHolder and still has * NFAVertex as its vertex descriptor */ - typedef ue2::unordered_set EdgeSet; + typedef unordered_set EdgeSet; EdgeSet deadEdges; // We don't have indices spanning [0,N] on our filtered graph, so we // provide a colour map. - ue2::unordered_map colours; + unordered_map colours; depth_first_search(g, visitor(BackEdges(deadEdges)). color_map(make_assoc_property_map(colours))); @@ -155,22 +159,22 @@ vector buildTopoOrder(const RepeatGraph &g) { static void proper_pred(const NGHolder &g, NFAVertex v, - ue2::unordered_set &p) { + unordered_set &p) { pred(g, v, &p); p.erase(v); // self-loops } static void proper_succ(const NGHolder &g, NFAVertex v, - ue2::unordered_set &s) { + unordered_set &s) { succ(g, v, &s); s.erase(v); // self-loops } static bool roguePredecessor(const NGHolder &g, NFAVertex v, - const ue2::unordered_set &involved, - const ue2::unordered_set &pred) { + const unordered_set &involved, + const unordered_set &pred) { u32 seen = 0; for (auto u : inv_adjacent_vertices_range(v, g)) { @@ -195,8 +199,8 @@ bool roguePredecessor(const NGHolder &g, NFAVertex v, static bool rogueSuccessor(const NGHolder &g, NFAVertex v, - const ue2::unordered_set &involved, - const ue2::unordered_set &succ) { + const unordered_set &involved, + const unordered_set &succ) { u32 seen = 0; for (auto w : adjacent_vertices_range(v, g)) { if (contains(involved, w)) { @@ -245,10 +249,10 @@ bool hasDifferentTops(const NGHolder &g, const vector &verts) { static bool vertexIsBad(const NGHolder &g, NFAVertex v, - const ue2::unordered_set &involved, - const ue2::unordered_set &tail, - const ue2::unordered_set &pred, - const ue2::unordered_set &succ, + const unordered_set &involved, + const unordered_set &tail, + const unordered_set &pred, + const unordered_set &succ, const flat_set &reports) { DEBUG_PRINTF("check vertex %zu\n", g[v].index); @@ -293,13 +297,13 @@ void splitSubgraph(const NGHolder &g, const deque &verts, // We construct a copy of the graph using just the vertices we want, rather // than using a filtered_graph -- this way is faster. NGHolder verts_g; - ue2::unordered_map verts_map; // in g -> in verts_g + unordered_map verts_map; // in g -> in verts_g fillHolder(&verts_g, g, verts, &verts_map); - ue2::unordered_map old2new; + unordered_map old2new; auto ug = createUnGraph(verts_g, true, true, old2new); - ue2::unordered_map repeatMap; + unordered_map repeatMap; size_t num = connected_components(ug, make_assoc_property_map(repeatMap)); DEBUG_PRINTF("found %zu connected repeat components\n", num); @@ -377,10 +381,10 @@ void checkReachSubgraphs(const NGHolder &g, vector &rs, continue; } - ue2::unordered_set involved(rsi.vertices.begin(), - rsi.vertices.end()); - ue2::unordered_set tail(involved); // to look for back-edges. - ue2::unordered_set pred, succ; + unordered_set involved(rsi.vertices.begin(), + rsi.vertices.end()); + unordered_set tail(involved); // to look for back-edges. + unordered_set pred, succ; proper_pred(g, rsi.vertices.front(), pred); proper_succ(g, rsi.vertices.back(), succ); @@ -514,7 +518,7 @@ bool processSubgraph(const NGHolder &g, ReachSubgraph &rsi, NFAVertex first = rsi.vertices.front(); NFAVertex last = rsi.vertices.back(); - typedef ue2::unordered_map DistanceMap; + typedef unordered_map DistanceMap; DistanceMap dist; // Initial distance sets. @@ -608,7 +612,7 @@ bool processSubgraph(const NGHolder &g, ReachSubgraph &rsi, static bool allPredsInSubgraph(NFAVertex v, const NGHolder &g, - const ue2::unordered_set &involved) { + const unordered_set &involved) { for (auto u : inv_adjacent_vertices_range(v, g)) { if (!contains(involved, u)) { return false; @@ -619,8 +623,8 @@ bool allPredsInSubgraph(NFAVertex v, const NGHolder &g, static void buildTugTrigger(NGHolder &g, NFAVertex cyclic, NFAVertex v, - const ue2::unordered_set &involved, - ue2::unordered_map &depths, + const unordered_set &involved, + unordered_map &depths, vector &tugs) { if (allPredsInSubgraph(v, g, involved)) { // We can transform this vertex into a tug trigger in-place. @@ -699,7 +703,7 @@ u32 unpeelAmount(const NGHolder &g, const ReachSubgraph &rsi) { static void unpeelNearEnd(NGHolder &g, ReachSubgraph &rsi, - ue2::unordered_map &depths, + unordered_map &depths, vector *succs) { u32 unpeel = unpeelAmount(g, rsi); DEBUG_PRINTF("unpeeling %u vertices\n", unpeel); @@ -759,8 +763,8 @@ void getSuccessors(const NGHolder &g, const ReachSubgraph &rsi, static void replaceSubgraphWithSpecial(NGHolder &g, ReachSubgraph &rsi, vector *repeats, - ue2::unordered_map &depths, - ue2::unordered_set &created) { + unordered_map &depths, + unordered_set &created) { assert(!rsi.bad); assert(rsi.repeatMin > depth(0)); assert(rsi.repeatMax >= rsi.repeatMin); @@ -768,7 +772,7 @@ void replaceSubgraphWithSpecial(NGHolder &g, ReachSubgraph &rsi, DEBUG_PRINTF("entry\n"); - const ue2::unordered_set involved(rsi.vertices.begin(), + const unordered_set involved(rsi.vertices.begin(), rsi.vertices.end()); vector succs; getSuccessors(g, rsi, &succs); @@ -829,16 +833,16 @@ void replaceSubgraphWithSpecial(NGHolder &g, ReachSubgraph &rsi, static void replaceSubgraphWithLazySpecial(NGHolder &g, ReachSubgraph &rsi, vector *repeats, - ue2::unordered_map &depths, - ue2::unordered_set &created) { + unordered_map &depths, + unordered_set &created) { assert(!rsi.bad); assert(rsi.repeatMin); assert(rsi.repeatMax >= rsi.repeatMin); DEBUG_PRINTF("entry\n"); - const ue2::unordered_set involved(rsi.vertices.begin(), - rsi.vertices.end()); + const unordered_set involved(rsi.vertices.begin(), + rsi.vertices.end()); vector succs; getSuccessors(g, rsi, &succs); @@ -932,7 +936,7 @@ void reprocessSubgraph(const NGHolder &h, const Grey &grey, * involved in other repeats as a result of earlier repeat transformations. */ static bool peelSubgraph(const NGHolder &g, const Grey &grey, ReachSubgraph &rsi, - const ue2::unordered_set &created) { + const unordered_set &created) { assert(!rsi.bad); if (created.empty()) { @@ -994,8 +998,8 @@ bool peelSubgraph(const NGHolder &g, const Grey &grey, ReachSubgraph &rsi, * idea to extend to cyclic states, too. */ static void peelStartDotStar(const NGHolder &g, - const ue2::unordered_map &depths, - const Grey &grey, ReachSubgraph &rsi) { + const unordered_map &depths, + const Grey &grey, ReachSubgraph &rsi) { if (rsi.vertices.size() < 1) { return; } @@ -1073,8 +1077,8 @@ bool hasSkipEdges(const NGHolder &g, const ReachSubgraph &rsi) { /* depth info is valid as calculated at entry */ static bool entered_at_fixed_offset(NFAVertex v, const NGHolder &g, - const ue2::unordered_map &depths, - const ue2::unordered_set &reached_by_fixed_tops) { + const unordered_map &depths, + const unordered_set &reached_by_fixed_tops) { DEBUG_PRINTF("|reached_by_fixed_tops| %zu\n", reached_by_fixed_tops.size()); if (is_triggered(g) && !contains(reached_by_fixed_tops, v)) { @@ -1200,12 +1204,12 @@ CharReach predReach(const NGHolder &g, NFAVertex v) { */ static void filterMap(const NGHolder &subg, - ue2::unordered_map &vmap) { + unordered_map &vmap) { NGHolder::vertex_iterator vi, ve; tie(vi, ve) = vertices(subg); - const ue2::unordered_set remaining_verts(vi, ve); + const unordered_set remaining_verts(vi, ve); - ue2::unordered_map fmap; // filtered map + unordered_map fmap; // filtered map for (const auto &m : vmap) { if (contains(remaining_verts, m.second)) { @@ -1220,7 +1224,7 @@ void filterMap(const NGHolder &subg, * the bounded repeat. */ static void buildRepeatGraph(NGHolder &rg, - ue2::unordered_map &rg_map, + unordered_map &rg_map, const NGHolder &g, const ReachSubgraph &rsi, const map>> &triggers) { cloneHolder(rg, g, &rg_map); @@ -1231,7 +1235,7 @@ void buildRepeatGraph(NGHolder &rg, add_edge(rg.accept, rg.acceptEod, rg); // Find the set of vertices in rg involved in the repeat. - ue2::unordered_set rg_involved; + unordered_set rg_involved; for (const auto &v : rsi.vertices) { assert(contains(rg_map, v)); rg_involved.insert(rg_map.at(v)); @@ -1273,7 +1277,7 @@ void buildRepeatGraph(NGHolder &rg, */ static void buildInputGraph(NGHolder &lhs, - ue2::unordered_map &lhs_map, + unordered_map &lhs_map, const NGHolder &g, const NFAVertex first, const map>> &triggers) { DEBUG_PRINTF("building lhs with first=%zu\n", g[first].index); @@ -1327,8 +1331,8 @@ static const size_t MAX_SOLE_ENTRY_VERTICES = 10000; * single offset at runtime. See UE-1361. */ static bool hasSoleEntry(const NGHolder &g, const ReachSubgraph &rsi, - const ue2::unordered_map &depths, - const ue2::unordered_set &reached_by_fixed_tops, + const unordered_map &depths, + const unordered_set &reached_by_fixed_tops, const map>> &triggers) { DEBUG_PRINTF("checking repeat {%s,%s}\n", rsi.repeatMin.str().c_str(), rsi.repeatMax.str().c_str()); @@ -1358,12 +1362,12 @@ bool hasSoleEntry(const NGHolder &g, const ReachSubgraph &rsi, } NGHolder rg; - ue2::unordered_map rg_map; + unordered_map rg_map; buildRepeatGraph(rg, rg_map, g, rsi, triggers); assert(rg.kind == g.kind); NGHolder lhs; - ue2::unordered_map lhs_map; + unordered_map lhs_map; buildInputGraph(lhs, lhs_map, g, first, triggers); assert(lhs.kind == g.kind); @@ -1377,7 +1381,7 @@ bool hasSoleEntry(const NGHolder &g, const ReachSubgraph &rsi, // are in one region, vertices in the bounded repeat are in another. const u32 lhs_region = 1; const u32 repeat_region = 2; - ue2::unordered_map region_map; + unordered_map region_map; for (const auto &v : rsi.vertices) { assert(!is_special(v, g)); // no specials in repeats @@ -1473,7 +1477,7 @@ struct StrawWalker { NFAVertex walk(NFAVertex v, vector &straw) const { DEBUG_PRINTF("walk from %zu\n", g[v].index); - ue2::unordered_set visited; + unordered_set visited; straw.clear(); while (!is_special(v, g)) { @@ -1695,7 +1699,7 @@ vector> getRepeatTriggers(const NGHolder &g, assert(!done.empty()); // Convert our path list into a set of unique triggers. - ue2::unordered_set> unique_triggers; + ue2_unordered_set> unique_triggers; for (const auto &path : done) { vector reach_path; for (auto jt = path.rbegin(), jte = path.rend(); jt != jte; ++jt) { @@ -1743,8 +1747,8 @@ static void selectHistoryScheme(const NGHolder &g, const ReportManager *rm, ReachSubgraph &rsi, - const ue2::unordered_map &depths, - const ue2::unordered_set &reached_by_fixed_tops, + const unordered_map &depths, + const unordered_set &reached_by_fixed_tops, const map>> &triggers, const vector &all_repeats, const bool simple_model_selection) { @@ -1812,7 +1816,7 @@ selectHistoryScheme(const NGHolder &g, const ReportManager *rm, static void buildFeeder(NGHolder &g, const BoundedRepeatData &rd, - ue2::unordered_set &created, + unordered_set &created, const vector &straw) { if (!g[rd.cyclic].char_reach.all()) { // Create another cyclic feeder state with flipped reach. It has an @@ -1859,7 +1863,7 @@ void buildFeeder(NGHolder &g, const BoundedRepeatData &rd, */ static bool improveLeadingRepeat(NGHolder &g, BoundedRepeatData &rd, - ue2::unordered_set &created, + unordered_set &created, const vector &all_repeats) { assert(edge(g.startDs, g.startDs, g).second); @@ -1963,7 +1967,7 @@ vector makeOwnStraw(NGHolder &g, BoundedRepeatData &rd, */ static bool improveLeadingRepeatOutfix(NGHolder &g, BoundedRepeatData &rd, - ue2::unordered_set &created, + unordered_set &created, const vector &all_repeats) { assert(g.kind == NFA_OUTFIX); @@ -2061,7 +2065,7 @@ bool endsInAcceptEod(const NGHolder &g, const ReachSubgraph &rsi) { namespace { class pfti_visitor : public boost::default_dfs_visitor { public: - pfti_visitor(ue2::unordered_map &top_depths_in, + pfti_visitor(unordered_map &top_depths_in, const depth &our_depth_in) : top_depths(top_depths_in), our_depth(our_depth_in) {} @@ -2077,7 +2081,7 @@ public: top_depths[v] = our_depth; } } - ue2::unordered_map &top_depths; + unordered_map &top_depths; const depth &our_depth; }; } // namespace @@ -2091,7 +2095,7 @@ void populateFixedTopInfo(const map &fixed_depth_tops, } assert(!proper_out_degree(g.startDs, g)); - ue2::unordered_map top_depths; + unordered_map top_depths; auto colours = make_small_color_map(g); for (const auto &e : out_edges_range(g.start, g)) { @@ -2142,7 +2146,7 @@ void populateFixedTopInfo(const map &fixed_depth_tops, static bool hasOverlappingRepeats(UNUSED const NGHolder &g, const vector &repeats) { - ue2::unordered_set involved; + unordered_set involved; for (const auto &br : repeats) { if (contains(involved, br.cyclic)) { @@ -2177,7 +2181,7 @@ bool hasOverlappingRepeats(UNUSED const NGHolder &g, */ static bool repeatIsNasty(const NGHolder &g, const ReachSubgraph &rsi, - const ue2::unordered_map &depths) { + const unordered_map &depths) { if (num_vertices(g) > NFA_MAX_STATES) { // We may have no choice but to implement this repeat to get the graph // down to a tractable number of vertices. @@ -2236,7 +2240,7 @@ void analyseRepeats(NGHolder &g, const ReportManager *rm, // Later on, we're (a little bit) dependent on depth information for // unpeeling and so forth. Note that these depths MUST be maintained when // new vertices are added. - ue2::unordered_map depths; + unordered_map depths; findInitDepths(g, depths); // Construct our list of subgraphs with the same reach using BGL magic. @@ -2293,13 +2297,13 @@ void analyseRepeats(NGHolder &g, const ReportManager *rm, // could make this unnecessary? const unique_ptr orig_g(cloneHolder(g)); - ue2::unordered_set reached_by_fixed_tops; + unordered_set reached_by_fixed_tops; if (is_triggered(g)) { populateFixedTopInfo(fixed_depth_tops, g, &reached_by_fixed_tops); } // Go to town on the remaining acceptable subgraphs. - ue2::unordered_set created; + unordered_set created; for (auto &rsi : rs) { DEBUG_PRINTF("subgraph (beginning vertex %zu) is a {%s,%s} repeat\n", g[rsi.vertices.front()].index, diff --git a/src/nfagraph/ng_repeat.h b/src/nfagraph/ng_repeat.h index 2f14cb0c..cfd804b7 100644 --- a/src/nfagraph/ng_repeat.h +++ b/src/nfagraph/ng_repeat.h @@ -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: @@ -37,7 +37,7 @@ #include "ue2common.h" #include "nfa/repeat_internal.h" #include "util/depth.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include #include @@ -122,7 +122,7 @@ void findRepeats(const NGHolder &h, u32 minRepeatVertices, struct PureRepeat { CharReach reach; DepthMinMax bounds; - ue2::flat_set reports; + flat_set reports; bool operator==(const PureRepeat &a) const { return reach == a.reach && bounds == a.bounds && reports == a.reports; diff --git a/src/nfagraph/ng_restructuring.cpp b/src/nfagraph/ng_restructuring.cpp index 32cdac23..704697e5 100644 --- a/src/nfagraph/ng_restructuring.cpp +++ b/src/nfagraph/ng_restructuring.cpp @@ -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: @@ -131,9 +131,9 @@ void getStateOrdering(NGHolder &g, const flat_set &tops, // Returns the number of states. static -ue2::unordered_map +unordered_map getStateIndices(const NGHolder &h, const vector &ordering) { - ue2::unordered_map states; + unordered_map states; for (const auto &v : vertices_range(h)) { states[v] = NO_STATE; } diff --git a/src/nfagraph/ng_restructuring.h b/src/nfagraph/ng_restructuring.h index bbd478d5..75d19c62 100644 --- a/src/nfagraph/ng_restructuring.h +++ b/src/nfagraph/ng_restructuring.h @@ -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: @@ -28,14 +28,16 @@ /** \file * \brief State numbering and late graph restructuring code. - */ + #ifndef NG_RESTRUCTURING_H #define NG_RESTRUCTURING_H #include "ng_holder.h" #include "ue2common.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" + +#include namespace ue2 { @@ -48,14 +50,14 @@ static constexpr u32 NO_STATE = ~0; /** * \brief Gives each participating vertex in the graph a unique state index. */ -unordered_map +std::unordered_map numberStates(NGHolder &h, const flat_set &tops); /** * \brief Counts the number of states (vertices with state indices) in the * graph. */ -u32 countStates(const unordered_map &state_ids); +u32 countStates(const std::unordered_map &state_ids); } // namespace ue2 diff --git a/src/nfagraph/ng_revacc.cpp b/src/nfagraph/ng_revacc.cpp index dc86dd44..0f932668 100644 --- a/src/nfagraph/ng_revacc.cpp +++ b/src/nfagraph/ng_revacc.cpp @@ -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: @@ -40,6 +40,8 @@ #include "util/charreach.h" #include "util/graph_range.h" +#include + using namespace std; namespace ue2 { diff --git a/src/nfagraph/ng_som.cpp b/src/nfagraph/ng_som.cpp index 67438103..6520a590 100644 --- a/src/nfagraph/ng_som.cpp +++ b/src/nfagraph/ng_som.cpp @@ -69,6 +69,8 @@ #include #include +#include +#include #include using namespace std; @@ -103,7 +105,7 @@ struct som_plan { static bool regionCanEstablishSom(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const u32 region, const vector &r_exits, const vector &depths) { if (region == regions.at(g.accept) || @@ -149,7 +151,7 @@ struct region_info { static void buildRegionMapping(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, map &info, bool include_region_0 = false) { for (auto v : vertices_range(g)) { @@ -228,7 +230,7 @@ void buildRegionMapping(const NGHolder &g, static bool validateXSL(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const u32 region, const CharReach &escapes, u32 *bad_region) { /* need to check that the escapes escape all of the graph past region */ u32 first_bad_region = ~0U; @@ -251,7 +253,7 @@ bool validateXSL(const NGHolder &g, static bool validateEXSL(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const u32 region, const CharReach &escapes, const NGHolder &prefix, u32 *bad_region) { /* EXSL: To be a valid EXSL with escapes e, we require that all states @@ -353,7 +355,7 @@ bool isPossibleLock(const NGHolder &g, static unique_ptr -makePrefix(const NGHolder &g, const ue2::unordered_map ®ions, +makePrefix(const NGHolder &g, const unordered_map ®ions, const region_info &curr, const region_info &next, bool renumber = true) { const vector &curr_exits = curr.exits; @@ -368,12 +370,12 @@ makePrefix(const NGHolder &g, const ue2::unordered_map ®ions, deque lhs_verts; insert(&lhs_verts, lhs_verts.end(), vertices(g)); - ue2::unordered_map lhs_map; // g -> prefix + unordered_map lhs_map; // g -> prefix fillHolder(&prefix, g, lhs_verts, &lhs_map); prefix.kind = NFA_OUTFIX; // We need a reverse mapping to track regions. - ue2::unordered_map rev_map; // prefix -> g + unordered_map rev_map; // prefix -> g for (const auto &e : lhs_map) { rev_map.emplace(e.second, e.first); } @@ -541,7 +543,7 @@ void setMidfixReports(ReportManager &rm, const som_plan &item, static bool finalRegion(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, NFAVertex v) { u32 region = regions.at(v); for (auto w : adjacent_vertices_range(v, g)) { @@ -771,7 +773,7 @@ void fillHolderForLockCheck(NGHolder *out, const NGHolder &g, static void fillRoughMidfix(NGHolder *out, const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, map::const_iterator picked) { /* as we are not the first prefix, we are probably not acyclic. We need to @@ -941,7 +943,7 @@ bool isMandRegionBetween(map::const_iterator a, // (woot!); updates picked, plan and bad_region. static bool advancePlan(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const NGHolder &prefix, bool stuck, map::const_iterator &picked, const map::const_iterator furthest, @@ -1051,13 +1053,12 @@ void addReporterVertices(const region_info &r, const NGHolder &g, // Fetches the mappings of all preds of {accept, acceptEod} in this region. static void addMappedReporterVertices(const region_info &r, const NGHolder &g, - const ue2::unordered_map &mapping, + const unordered_map &mapping, vector &reporters) { for (auto v : r.exits) { if (edge(v, g.accept, g).second || edge(v, g.acceptEod, g).second) { DEBUG_PRINTF("adding v=%zu\n", g[v].index); - ue2::unordered_map::const_iterator it = - mapping.find(v); + auto it = mapping.find(v); assert(it != mapping.end()); reporters.push_back(it->second); } @@ -1068,9 +1069,9 @@ void addMappedReporterVertices(const region_info &r, const NGHolder &g, // from earlier regions. static void cloneGraphWithOneEntry(NGHolder &out, const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, NFAVertex entry, const vector &enters, - ue2::unordered_map &orig_to_copy) { + unordered_map &orig_to_copy) { orig_to_copy.clear(); cloneHolder(out, g, &orig_to_copy); @@ -1095,7 +1096,7 @@ void cloneGraphWithOneEntry(NGHolder &out, const NGHolder &g, } static -void expandGraph(NGHolder &g, ue2::unordered_map ®ions, +void expandGraph(NGHolder &g, unordered_map ®ions, vector &enters) { assert(!enters.empty()); const u32 split_region = regions.at(enters.front()); @@ -1178,11 +1179,11 @@ void expandGraph(NGHolder &g, ue2::unordered_map ®ions, static bool doTreePlanningIntl(NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, map::const_iterator picked, u32 bad_region, u32 parent_plan, - const ue2::unordered_map ©_to_orig, + const unordered_map ©_to_orig, vector &plan, const Grey &grey) { assert(picked != info.end()); @@ -1341,7 +1342,7 @@ bool doTreePlanning(NGHolder &g, // regions. NGHolder g_path; - ue2::unordered_map orig_to_copy; + unordered_map orig_to_copy; cloneGraphWithOneEntry(g_path, g, g_regions, v, enters, orig_to_copy); auto regions = assignRegions(g_path); dumpHolder(g_path, regions, 14, "som_treepath", grey); @@ -1375,7 +1376,7 @@ bool doTreePlanning(NGHolder &g, } // Construct reverse mapping from vertices in g_path to g. - ue2::unordered_map copy_to_orig; + unordered_map copy_to_orig; for (const auto &m : orig_to_copy) { copy_to_orig.insert(make_pair(m.second, m.first)); } @@ -1398,7 +1399,7 @@ enum dsp_behaviour { static bool doSomPlanning(NGHolder &g, bool stuck_in, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, map::const_iterator picked, vector &plan, @@ -1940,7 +1941,7 @@ map::const_iterator findLaterLiteral(const NGHolder &g, static bool attemptToBuildChainAfterSombe(SomSlotManager &ssm, NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, map::const_iterator picked, const Grey &grey, @@ -2014,7 +2015,7 @@ void setReportOnHaigPrefix(RoseBuild &rose, NGHolder &h) { static bool tryHaig(RoseBuild &rose, NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, som_type som, u32 somPrecision, map::const_iterator picked, shared_ptr *haig, shared_ptr *haig_prefix, @@ -2062,7 +2063,7 @@ void roseAddHaigLiteral(RoseBuild &tb, const shared_ptr &prefix, static sombe_rv doHaigLitSom(NG &ng, NGHolder &g, const ExpressionInfo &expr, u32 comp_id, som_type som, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, map::const_iterator lower_bound) { DEBUG_PRINTF("entry\n"); @@ -2343,7 +2344,7 @@ bool splitOffLeadingLiterals(const NGHolder &g, set *lit_out, } } - ue2::unordered_map rhs_map; + unordered_map rhs_map; vector pivots; insert(&pivots, pivots.end(), adj_term1); splitRHS(g, pivots, rhs, &rhs_map); @@ -2354,7 +2355,7 @@ bool splitOffLeadingLiterals(const NGHolder &g, set *lit_out, static void findBestLiteral(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, ue2_literal *lit_out, NFAVertex *v, const CompileContext &cc) { map info; @@ -2394,7 +2395,7 @@ void findBestLiteral(const NGHolder &g, static bool splitOffBestLiteral(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, ue2_literal *lit_out, NGHolder *lhs, NGHolder *rhs, const CompileContext &cc) { NFAVertex v = NGHolder::null_vertex(); @@ -2406,8 +2407,8 @@ bool splitOffBestLiteral(const NGHolder &g, DEBUG_PRINTF("literal is '%s'\n", dumpString(*lit_out).c_str()); - ue2::unordered_map lhs_map; - ue2::unordered_map rhs_map; + unordered_map lhs_map; + unordered_map rhs_map; splitGraph(g, v, lhs, &lhs_map, rhs, &rhs_map); @@ -2498,7 +2499,7 @@ bool doLitHaigSom(NG &ng, NGHolder &g, som_type som) { static bool doHaigLitHaigSom(NG &ng, NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, som_type som) { if (!ng.cc.grey.allowLitHaig) { return false; @@ -2732,7 +2733,7 @@ bool trySombe(NG &ng, NGHolder &g, som_type som) { static map::const_iterator pickInitialSomCut(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, const vector &depths) { map::const_iterator picked = info.end(); @@ -2757,7 +2758,7 @@ map::const_iterator pickInitialSomCut(const NGHolder &g, static map::const_iterator tryForLaterRevNfaCut(const NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, const vector &depths, const map::const_iterator &orig, @@ -2849,7 +2850,7 @@ map::const_iterator tryForLaterRevNfaCut(const NGHolder &g, static unique_ptr makePrefixForChain(NGHolder &g, - const ue2::unordered_map ®ions, + const unordered_map ®ions, const map &info, const map::const_iterator &picked, vector *depths, bool prefix_by_rev, diff --git a/src/nfagraph/ng_som_util.cpp b/src/nfagraph/ng_som_util.cpp index a3b6ee5f..1e7a41bb 100644 --- a/src/nfagraph/ng_som_util.cpp +++ b/src/nfagraph/ng_som_util.cpp @@ -54,7 +54,7 @@ vector getDistancesFromSOM(const NGHolder &g_orig) { // We operate on a temporary copy of the original graph here, so we don't // have to mutate the original. NGHolder g; - ue2::unordered_map vmap; // vertex in g_orig to vertex in g + unordered_map vmap; // vertex in g_orig to vertex in g cloneHolder(g, g_orig, &vmap); vector vstarts; @@ -136,7 +136,7 @@ bool firstMatchIsFirst(const NGHolder &p) { return false; } - ue2::flat_set states; + flat_set states; /* turn on all states (except starts - avoid suffix matches) */ /* If we were doing (1) we would also except states leading to accepts - avoid prefix matches */ @@ -166,7 +166,7 @@ bool firstMatchIsFirst(const NGHolder &p) { } bool somMayGoBackwards(NFAVertex u, const NGHolder &g, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, smgb_cache &cache) { /* Need to ensure all matches of the graph g up to u contain no infixes * which are also matches of the graph to u. @@ -215,7 +215,7 @@ bool somMayGoBackwards(NFAVertex u, const NGHolder &g, } } - ue2::unordered_map orig_to_copy; + unordered_map orig_to_copy; NGHolder c_g; cloneHolder(c_g, g, &orig_to_copy); @@ -287,7 +287,7 @@ bool somMayGoBackwards(NFAVertex u, const NGHolder &g, } bool sentClearsTail(const NGHolder &g, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, const NGHolder &sent, u32 last_head_region, u32 *bad_region) { /* if a subsequent match from the prefix clears the rest of the pattern @@ -312,7 +312,7 @@ bool sentClearsTail(const NGHolder &g, */ u32 first_bad_region = ~0U; - ue2::flat_set states; + flat_set states; /* turn on all states */ DEBUG_PRINTF("region %u is cutover\n", last_head_region); for (auto v : vertices_range(g)) { diff --git a/src/nfagraph/ng_som_util.h b/src/nfagraph/ng_som_util.h index 793dd2c3..e2d38642 100644 --- a/src/nfagraph/ng_som_util.h +++ b/src/nfagraph/ng_som_util.h @@ -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: @@ -35,9 +35,9 @@ #include "ng_util.h" #include "util/depth.h" -#include "util/ue2_containers.h" #include +#include #include namespace ue2 { @@ -61,7 +61,7 @@ struct smgb_cache : public mbsb_cache { }; bool somMayGoBackwards(NFAVertex u, const NGHolder &g, - const ue2::unordered_map ®ion_map, + const std::unordered_map ®ion_map, smgb_cache &cache); /** @@ -75,7 +75,7 @@ bool somMayGoBackwards(NFAVertex u, const NGHolder &g, * region ID associated with a tail state that is still on. */ bool sentClearsTail(const NGHolder &g, - const ue2::unordered_map ®ion_map, + const std::unordered_map ®ion_map, const NGHolder &sent, u32 last_head_region, u32 *bad_region); diff --git a/src/nfagraph/ng_split.cpp b/src/nfagraph/ng_split.cpp index 3c2baee4..91a099fc 100644 --- a/src/nfagraph/ng_split.cpp +++ b/src/nfagraph/ng_split.cpp @@ -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: @@ -37,7 +37,6 @@ #include "util/container.h" #include "util/graph.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" #include #include @@ -63,12 +62,13 @@ void clearAccepts(NGHolder &g) { } static -void filterSplitMap(const NGHolder &g, ue2::unordered_map *out_map) { - ue2::unordered_set verts; +void filterSplitMap(const NGHolder &g, + unordered_map *out_map) { + unordered_set verts; insert(&verts, vertices(g)); - ue2::unordered_map::iterator it = out_map->begin(); + auto it = out_map->begin(); while (it != out_map->end()) { - ue2::unordered_map::iterator jt = it; + auto jt = it; ++it; if (!contains(verts, jt->second)) { out_map->erase(jt); @@ -78,8 +78,8 @@ void filterSplitMap(const NGHolder &g, ue2::unordered_map static void splitLHS(const NGHolder &base, const vector &pivots, - const vector &rhs_pivots, - NGHolder *lhs, ue2::unordered_map *lhs_map) { + const vector &rhs_pivots, NGHolder *lhs, + unordered_map *lhs_map) { assert(lhs && lhs_map); cloneHolder(*lhs, base, lhs_map); @@ -131,7 +131,7 @@ void splitLHS(const NGHolder &base, const vector &pivots, } void splitLHS(const NGHolder &base, NFAVertex pivot, - NGHolder *lhs, ue2::unordered_map *lhs_map) { + NGHolder *lhs, unordered_map *lhs_map) { vector pivots(1, pivot); vector rhs_pivots; insert(&rhs_pivots, rhs_pivots.end(), adjacent_vertices(pivot, base)); @@ -139,7 +139,7 @@ void splitLHS(const NGHolder &base, NFAVertex pivot, } void splitRHS(const NGHolder &base, const vector &pivots, - NGHolder *rhs, ue2::unordered_map *rhs_map) { + NGHolder *rhs, unordered_map *rhs_map) { assert(rhs && rhs_map); cloneHolder(*rhs, base, rhs_map); @@ -211,8 +211,8 @@ void findCommonSuccessors(const NGHolder &g, const vector &pivots, } void splitGraph(const NGHolder &base, const vector &pivots, - NGHolder *lhs, ue2::unordered_map *lhs_map, - NGHolder *rhs, ue2::unordered_map *rhs_map) { + NGHolder *lhs, unordered_map *lhs_map, + NGHolder *rhs, unordered_map *rhs_map) { DEBUG_PRINTF("splitting graph at %zu vertices\n", pivots.size()); assert(!has_parallel_edge(base)); @@ -235,8 +235,8 @@ void splitGraph(const NGHolder &base, const vector &pivots, } void splitGraph(const NGHolder &base, NFAVertex pivot, - NGHolder *lhs, ue2::unordered_map *lhs_map, - NGHolder *rhs, ue2::unordered_map *rhs_map) { + NGHolder *lhs, unordered_map *lhs_map, + NGHolder *rhs, unordered_map *rhs_map) { vector pivots(1, pivot); splitGraph(base, pivots, lhs, lhs_map, rhs, rhs_map); } diff --git a/src/nfagraph/ng_split.h b/src/nfagraph/ng_split.h index 31c1cf35..9ddc0332 100644 --- a/src/nfagraph/ng_split.h +++ b/src/nfagraph/ng_split.h @@ -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: @@ -33,10 +33,10 @@ #ifndef NG_SPLIT_H #define NG_SPLIT_H -#include - #include "ng_holder.h" -#include "util/ue2_containers.h" + +#include +#include namespace ue2 { @@ -55,21 +55,21 @@ class NGHolder; * vertices which have an edge to every pivot */ void splitGraph(const NGHolder &base, NFAVertex pivot, NGHolder *lhs, - ue2::unordered_map *lhs_map, + std::unordered_map *lhs_map, NGHolder *rhs, - ue2::unordered_map *rhs_map); + std::unordered_map *rhs_map); void splitGraph(const NGHolder &base, const std::vector &pivots, NGHolder *lhs, - ue2::unordered_map *lhs_map, + std::unordered_map *lhs_map, NGHolder *rhs, - ue2::unordered_map *rhs_map); + std::unordered_map *rhs_map); void splitLHS(const NGHolder &base, NFAVertex pivot, NGHolder *lhs, - ue2::unordered_map *lhs_map); + std::unordered_map *lhs_map); void splitRHS(const NGHolder &base, const std::vector &pivots, - NGHolder *rhs, ue2::unordered_map *rhs_map); + NGHolder *rhs, std::unordered_map *rhs_map); } // namespace ue2 diff --git a/src/nfagraph/ng_squash.cpp b/src/nfagraph/ng_squash.cpp index ebec3a4a..df77668e 100644 --- a/src/nfagraph/ng_squash.cpp +++ b/src/nfagraph/ng_squash.cpp @@ -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: @@ -104,7 +104,6 @@ #include "ng_region.h" #include "ng_som_util.h" #include "ng_util.h" -#include "ng_util.h" #include "util/container.h" #include "util/graph_range.h" #include "util/report_manager.h" @@ -112,6 +111,8 @@ #include #include +#include +#include #include #include @@ -120,13 +121,11 @@ using namespace std; namespace ue2 { -typedef ue2::unordered_map > PostDomTree; +typedef unordered_map> PostDomTree; static void buildPDomTree(const NGHolder &g, PostDomTree &tree) { - ue2::unordered_map postdominators = - findPostDominators(g); + auto postdominators = findPostDominators(g); for (auto v : vertices_range(g)) { if (is_special(v, g)) { @@ -150,7 +149,7 @@ void buildSquashMask(NFAStateSet &mask, const NGHolder &g, NFAVertex v, const CharReach &cr, const NFAStateSet &init, const vector &vByIndex, const PostDomTree &tree, som_type som, const vector &som_depths, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, smgb_cache &cache) { DEBUG_PRINTF("build base squash mask for vertex %zu)\n", g[v].index); @@ -274,7 +273,7 @@ void findDerivedSquashers(const NGHolder &g, const vector &vByIndex, const PostDomTree &pdom_tree, const NFAStateSet &init, map *squash, som_type som, const vector &som_depths, - const ue2::unordered_map ®ion_map, + const unordered_map ®ion_map, smgb_cache &cache) { deque remaining; for (const auto &m : *squash) { @@ -619,7 +618,7 @@ static vector findUnreachable(const NGHolder &g) { const boost::reverse_graph revg(g); - ue2::unordered_map colours; + unordered_map colours; colours.reserve(num_vertices(g)); depth_first_visit(revg, g.acceptEod, @@ -661,7 +660,7 @@ findHighlanderSquashers(const NGHolder &g, const ReportManager &rm) { // cutting the appropriate out-edges to accept and seeing which // vertices become unreachable. - ue2::unordered_map orig_to_copy; + unordered_map orig_to_copy; NGHolder h; cloneHolder(h, g, &orig_to_copy); removeEdgesToAccept(h, orig_to_copy[v]); diff --git a/src/nfagraph/ng_squash.h b/src/nfagraph/ng_squash.h index 66621a7d..51ce245a 100644 --- a/src/nfagraph/ng_squash.h +++ b/src/nfagraph/ng_squash.h @@ -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: @@ -35,7 +35,6 @@ #include "ng_holder.h" #include "som/som.h" #include "ue2common.h" -#include "util/ue2_containers.h" #include #include @@ -45,7 +44,9 @@ namespace ue2 { class NGHolder; class ReportManager; -/** Dynamically-sized bitset, as an NFA can have an arbitrary number of states. */ +/** + * Dynamically-sized bitset, as an NFA can have an arbitrary number of states. + */ typedef boost::dynamic_bitset<> NFAStateSet; /** diff --git a/src/nfagraph/ng_undirected.h b/src/nfagraph/ng_undirected.h index 1e27ad79..036adcbf 100644 --- a/src/nfagraph/ng_undirected.h +++ b/src/nfagraph/ng_undirected.h @@ -37,7 +37,7 @@ #include "ng_util.h" #include "ue2common.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" +#include "util/unordered.h" #include @@ -71,8 +71,8 @@ template NFAUndirectedGraph createUnGraph(const Graph &g, bool excludeStarts, bool excludeAccepts, - unordered_map &old2new) { + std::unordered_map &old2new) { NFAUndirectedGraph ug; size_t idx = 0; @@ -97,7 +97,7 @@ NFAUndirectedGraph createUnGraph(const Graph &g, // Track seen edges so that we don't insert parallel edges. using Vertex = typename Graph::vertex_descriptor; - unordered_set> seen; + ue2_unordered_set> seen; seen.reserve(num_edges(g)); auto make_ordered_edge = [](Vertex a, Vertex b) { return std::make_pair(std::min(a, b), std::max(a, b)); diff --git a/src/nfagraph/ng_util.cpp b/src/nfagraph/ng_util.cpp index 14082407..83b29257 100644 --- a/src/nfagraph/ng_util.cpp +++ b/src/nfagraph/ng_util.cpp @@ -48,6 +48,9 @@ #include #include #include +#include +#include + #include #include #include @@ -353,7 +356,7 @@ vector getTopoOrdering(const NGHolder &g) { // having to reallocate it, etc. auto colors = make_small_color_map(g); - using EdgeSet = ue2::unordered_set; + using EdgeSet = unordered_set; EdgeSet backEdges; BackEdges be(backEdges); @@ -467,7 +470,7 @@ void setTops(NGHolder &h, u32 top) { void clearReports(NGHolder &g) { DEBUG_PRINTF("clearing reports without an accept edge\n"); - ue2::unordered_set allow; + unordered_set allow; insert(&allow, inv_adjacent_vertices(g.accept, g)); insert(&allow, inv_adjacent_vertices(g.acceptEod, g)); allow.erase(g.accept); // due to stylised edge. @@ -491,7 +494,7 @@ void duplicateReport(NGHolder &g, ReportID r_old, ReportID r_new) { static void fillHolderOutEdges(NGHolder &out, const NGHolder &in, - const ue2::unordered_map &v_map, + const unordered_map &v_map, NFAVertex u) { NFAVertex u_new = v_map.at(u); @@ -513,9 +516,9 @@ void fillHolderOutEdges(NGHolder &out, const NGHolder &in, } void fillHolder(NGHolder *outp, const NGHolder &in, const deque &vv, - ue2::unordered_map *v_map_out) { + unordered_map *v_map_out) { NGHolder &out = *outp; - ue2::unordered_map &v_map = *v_map_out; + unordered_map &v_map = *v_map_out; out.kind = in.kind; @@ -597,7 +600,7 @@ void cloneHolder(NGHolder &out, const NGHolder &in) { } void cloneHolder(NGHolder &out, const NGHolder &in, - ue2::unordered_map *mapping) { + unordered_map *mapping) { cloneHolder(out, in); vector out_verts(num_vertices(in)); for (auto v : vertices_range(out)) { @@ -620,7 +623,7 @@ unique_ptr cloneHolder(const NGHolder &in) { void reverseHolder(const NGHolder &g_in, NGHolder &g) { // Make the BGL do the grunt work. - ue2::unordered_map vertexMap; + unordered_map vertexMap; boost::transpose_graph(g_in, g, orig_to_copy(boost::make_assoc_property_map(vertexMap))); diff --git a/src/nfagraph/ng_util.h b/src/nfagraph/ng_util.h index 4c529a83..3cc9c7c3 100644 --- a/src/nfagraph/ng_util.h +++ b/src/nfagraph/ng_util.h @@ -32,16 +32,17 @@ #ifndef NG_UTIL_H #define NG_UTIL_H -#include -#include +#include "ng_holder.h" +#include "ue2common.h" +#include "util/flat_containers.h" +#include "util/graph.h" +#include "util/graph_range.h" #include // for default_dfs_visitor -#include "ng_holder.h" -#include "ue2common.h" -#include "util/graph.h" -#include "util/graph_range.h" -#include "util/ue2_containers.h" +#include +#include +#include namespace ue2 { @@ -272,12 +273,12 @@ void appendLiteral(NGHolder &h, const ue2_literal &s); * \a in). A vertex mapping is returned in \a v_map_out. */ void fillHolder(NGHolder *outp, const NGHolder &in, const std::deque &vv, - unordered_map *v_map_out); + std::unordered_map *v_map_out); /** \brief Clone the graph in \a in into graph \a out, returning a vertex * mapping in \a v_map_out. */ void cloneHolder(NGHolder &out, const NGHolder &in, - unordered_map *v_map_out); + std::unordered_map *v_map_out); /** \brief Clone the graph in \a in into graph \a out. */ void cloneHolder(NGHolder &out, const NGHolder &in); diff --git a/src/nfagraph/ng_violet.cpp b/src/nfagraph/ng_violet.cpp index d3303985..6742fec9 100644 --- a/src/nfagraph/ng_violet.cpp +++ b/src/nfagraph/ng_violet.cpp @@ -57,13 +57,13 @@ #include "util/compare.h" #include "util/compile_context.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/graph_range.h" #include "util/make_unique.h" #include "util/order_check.h" #include "util/target_info.h" #include "util/ue2string.h" -#include "util/ue2_containers.h" #include #include @@ -559,7 +559,7 @@ void filterCandPivots(const NGHolder &g, const set &cand_raw, static void getCandidatePivots(const NGHolder &g, set *cand, set *cand_raw) { - ue2::unordered_map dominators = findDominators(g); + auto dominators = findDominators(g); set accepts; @@ -1023,8 +1023,8 @@ bool splitRoseEdge(const NGHolder &base_graph, RoseInGraph &vg, shared_ptr lhs = make_shared(); shared_ptr rhs = make_shared(); - ue2::unordered_map lhs_map; - ue2::unordered_map rhs_map; + unordered_map lhs_map; + unordered_map rhs_map; splitGraph(base_graph, splitters, lhs.get(), &lhs_map, rhs.get(), &rhs_map); DEBUG_PRINTF("split %s:%zu into %s:%zu + %s:%zu\n", @@ -1217,7 +1217,7 @@ void splitEdgesByCut(NGHolder &h, RoseInGraph &vg, NFAVertex pivot = target(e, h); DEBUG_PRINTF("splitting on pivot %zu\n", h[pivot].index); - ue2::unordered_map temp_map; + unordered_map temp_map; shared_ptr new_lhs = make_shared(); splitLHS(h, pivot, new_lhs.get(), &temp_map); @@ -1298,7 +1298,7 @@ void splitEdgesByCut(NGHolder &h, RoseInGraph &vg, effort */ if (!contains(done_rhs, adj)) { - ue2::unordered_map temp_map; + unordered_map temp_map; shared_ptr new_rhs = make_shared(); splitRHS(h, adj, new_rhs.get(), &temp_map); remove_edge(new_rhs->start, new_rhs->accept, *new_rhs); diff --git a/src/parser/Parser.rl b/src/parser/Parser.rl index ce9ca865..43dfc760 100644 --- a/src/parser/Parser.rl +++ b/src/parser/Parser.rl @@ -53,8 +53,8 @@ #include "parser/Parser.h" #include "ue2common.h" #include "util/compare.h" +#include "util/flat_containers.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" #include "util/unicode_def.h" #include "util/verify_types.h" diff --git a/src/parser/buildstate.cpp b/src/parser/buildstate.cpp index eb25550b..75cfbb7b 100644 --- a/src/parser/buildstate.cpp +++ b/src/parser/buildstate.cpp @@ -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: @@ -39,8 +39,10 @@ #include "nfagraph/ng_builder.h" #include "util/charreach.h" #include "util/container.h" +#include "util/flat_containers.h" +#include "util/hash.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" +#include "util/unordered.h" #include #include @@ -449,7 +451,7 @@ unique_ptr makeGlushkovBuildState(NFABuilder &b, * Scans through a list of positions and retains only the highest priority * version of a given (position, flags) entry. */ void cleanupPositions(vector &a) { - ue2::unordered_set> seen; // track dupes + ue2_unordered_set> seen; vector out; out.reserve(a.size()); // output should be close to input in size. diff --git a/src/parser/check_refs.cpp b/src/parser/check_refs.cpp index fae68f74..0badc780 100644 --- a/src/parser/check_refs.cpp +++ b/src/parser/check_refs.cpp @@ -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: @@ -36,7 +36,7 @@ #include "ConstComponentVisitor.h" #include "parse_error.h" #include "util/container.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include diff --git a/src/parser/check_refs.h b/src/parser/check_refs.h index ede44896..26912fb8 100644 --- a/src/parser/check_refs.h +++ b/src/parser/check_refs.h @@ -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: @@ -26,14 +26,16 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/** \file +/** + * \file * \brief Component tree analysis that checks that references (such as * back-refs, conditionals) have valid referents. */ -#ifndef PARSER_CHECK_REFS_H_ -#define PARSER_CHECK_REFS_H_ -#include "util/ue2_containers.h" +#ifndef PARSER_CHECK_REFS_H +#define PARSER_CHECK_REFS_H + +#include "util/flat_containers.h" #include @@ -43,8 +45,8 @@ class Component; class ComponentSequence; void checkReferences(const Component &root, unsigned int groupIndices, - const ue2::flat_set &groupNames); + const flat_set &groupNames); } // namespace ue2 -#endif // PARSER_CHECK_REFS_H_ +#endif // PARSER_CHECK_REFS_H diff --git a/src/rose/rose_build.h b/src/rose/rose_build.h index cbb925f7..2219f12e 100644 --- a/src/rose/rose_build.h +++ b/src/rose/rose_build.h @@ -42,8 +42,8 @@ #include "rose_in_graph.h" #include "util/bytecode_ptr.h" #include "util/charreach.h" +#include "util/flat_containers.h" #include "util/noncopyable.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" #include @@ -73,7 +73,7 @@ public: /** \brief True if we can not establish that at most a single callback will * be generated at a given offset from this set of reports. */ - virtual bool requiresDedupeSupport(const ue2::flat_set &reports) + virtual bool requiresDedupeSupport(const flat_set &reports) const = 0; }; @@ -85,7 +85,7 @@ public: /** \brief Adds a single literal. */ virtual void add(bool anchored, bool eod, const ue2_literal &lit, - const ue2::flat_set &ids) = 0; + const flat_set &ids) = 0; virtual bool addRose(const RoseInGraph &ig, bool prefilter) = 0; virtual bool addSombeRose(const RoseInGraph &ig) = 0; @@ -99,17 +99,17 @@ public: /** \brief Returns true if we were able to add it as a mask. */ virtual bool add(bool anchored, const std::vector &mask, - const ue2::flat_set &reports) = 0; + const flat_set &reports) = 0; /** \brief Attempts to add the graph to the anchored acyclic table. Returns * true on success. */ virtual bool addAnchoredAcyclic(const NGHolder &graph) = 0; virtual bool validateMask(const std::vector &mask, - const ue2::flat_set &reports, + const flat_set &reports, bool anchored, bool eod) const = 0; virtual void addMask(const std::vector &mask, - const ue2::flat_set &reports, bool anchored, + const flat_set &reports, bool anchored, bool eod) = 0; /** \brief Construct a runtime implementation. */ diff --git a/src/rose/rose_build_add.cpp b/src/rose/rose_build_add.cpp index 4c895caf..f36fa576 100644 --- a/src/rose/rose_build_add.cpp +++ b/src/rose/rose_build_add.cpp @@ -85,7 +85,7 @@ struct RoseBuildData : noncopyable { /** Edges we've transformed (in \ref transformAnchoredLiteralOverlap) which * require ANCH history to prevent overlap. */ - ue2::unordered_set anch_history_edges; + unordered_set anch_history_edges; /** True if we're tracking Start of Match. */ bool som; diff --git a/src/rose/rose_build_anchored.cpp b/src/rose/rose_build_anchored.cpp index 74626a82..8ea07c95 100644 --- a/src/rose/rose_build_anchored.cpp +++ b/src/rose/rose_build_anchored.cpp @@ -49,11 +49,12 @@ #include "util/compile_error.h" #include "util/container.h" #include "util/determinise.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/make_unique.h" #include "util/order_check.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" +#include "util/unordered.h" #include "util/verify_types.h" #include @@ -285,19 +286,16 @@ struct Holder_StateSet { bool operator==(const Holder_StateSet &b) const { return wdelay == b.wdelay && wrap_state == b.wrap_state; } -}; -size_t hash_value(const Holder_StateSet &s) { - size_t val = 0; - boost::hash_combine(val, s.wrap_state); - boost::hash_combine(val, s.wdelay); - return val; -} + size_t hash() const { + return hash_all(wrap_state, wdelay); + } +}; class Automaton_Holder { public: using StateSet = Holder_StateSet; - using StateMap = unordered_map; + using StateMap = ue2_unordered_map; explicit Automaton_Holder(const NGHolder &g_in) : g(g_in) { for (auto v : vertices_range(g)) { @@ -416,7 +414,7 @@ public: private: const NGHolder &g; - ue2::unordered_map vertexToIndex; + unordered_map vertexToIndex; vector indexToVertex; vector cr_by_index; StateSet init; @@ -712,7 +710,7 @@ int addAutomaton(RoseBuildImpl &build, const NGHolder &h, ReportID *remap) { static void setReports(NGHolder &h, const map> &reportMap, - const ue2::unordered_map &orig_to_copy) { + const unordered_map &orig_to_copy) { for (const auto &m : reportMap) { NFAVertex t = orig_to_copy.at(m.first); assert(!m.second.empty()); @@ -724,7 +722,7 @@ void setReports(NGHolder &h, const map> &reportMap, int addAnchoredNFA(RoseBuildImpl &build, const NGHolder &wrapper, const map> &reportMap) { NGHolder h; - ue2::unordered_map orig_to_copy; + unordered_map orig_to_copy; cloneHolder(h, wrapper, &orig_to_copy); clear_in_edges(h.accept, h); clear_in_edges(h.acceptEod, h); diff --git a/src/rose/rose_build_bytecode.cpp b/src/rose/rose_build_bytecode.cpp index a41f0322..e7fd6271 100644 --- a/src/rose/rose_build_bytecode.cpp +++ b/src/rose/rose_build_bytecode.cpp @@ -145,8 +145,8 @@ struct build_context : noncopyable { /** \brief Simple cache of programs written to engine blob, used for * deduplication. */ - ue2::unordered_map program_cache; + unordered_map program_cache; /** \brief State indices, for those roles that have them. * Each vertex present has a unique state index in the range @@ -155,7 +155,7 @@ struct build_context : noncopyable { /** \brief Mapping from queue index to bytecode offset for built engines * that have already been pushed into the engine_blob. */ - ue2::unordered_map engineOffsets; + unordered_map engineOffsets; /** \brief List of long literals (ones with CHECK_LONG_LIT instructions) * that need hash table support. */ @@ -1470,7 +1470,7 @@ bool buildLeftfixes(RoseBuildImpl &tbi, build_context &bc, map > infixTriggers; vector order; - unordered_map > succs; + unordered_map> succs; findInfixTriggers(tbi, &infixTriggers); if (cc.grey.allowTamarama && cc.streaming && !do_prefix) { @@ -2269,9 +2269,9 @@ bool hasMpvTrigger(const set &reports, const ReportManager &rm) { } static -bool anyEndfixMpvTriggers(const RoseBuildImpl &tbi) { - const RoseGraph &g = tbi.g; - ue2::unordered_set done; +bool anyEndfixMpvTriggers(const RoseBuildImpl &build) { + const RoseGraph &g = build.g; + unordered_set done; /* suffixes */ for (auto v : vertices_range(g)) { @@ -2283,14 +2283,14 @@ bool anyEndfixMpvTriggers(const RoseBuildImpl &tbi) { } done.insert(g[v].suffix); - if (hasMpvTrigger(all_reports(g[v].suffix), tbi.rm)) { + if (hasMpvTrigger(all_reports(g[v].suffix), build.rm)) { return true; } } /* outfixes */ - for (const auto &out : tbi.outfixes) { - if (hasMpvTrigger(all_reports(out), tbi.rm)) { + for (const auto &out : build.outfixes) { + if (hasMpvTrigger(all_reports(out), build.rm)) { return true; } } @@ -2588,7 +2588,7 @@ void buildLeftInfoTable(const RoseBuildImpl &tbi, build_context &bc, const RoseGraph &g = tbi.g; const CompileContext &cc = tbi.cc; - ue2::unordered_set done_core; + unordered_set done_core; leftTable.resize(leftfixCount); diff --git a/src/rose/rose_build_castle.cpp b/src/rose/rose_build_castle.cpp index a85a784f..59bab3b1 100644 --- a/src/rose/rose_build_castle.cpp +++ b/src/rose/rose_build_castle.cpp @@ -38,7 +38,6 @@ #include "util/container.h" #include "util/dump_charclass.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" #include @@ -55,7 +54,7 @@ namespace ue2 { static void makeCastle(LeftEngInfo &left, - unordered_map> &cache) { + unordered_map> &cache) { if (left.dfa || left.haig || left.castle) { return; } @@ -85,7 +84,7 @@ void makeCastle(LeftEngInfo &left, static void makeCastleSuffix(RoseBuildImpl &tbi, RoseVertex v, - ue2::unordered_map > &cache) { + unordered_map> &cache) { RoseSuffixInfo &suffix = tbi.g[v].suffix; if (!suffix.graph) { return; @@ -298,8 +297,8 @@ bool unmakeCastles(RoseBuildImpl &tbi) { } void remapCastleTops(RoseBuildImpl &tbi) { - ue2::unordered_map > rose_castles; - ue2::unordered_map > suffix_castles; + unordered_map> rose_castles; + unordered_map> suffix_castles; RoseGraph &g = tbi.g; for (auto v : vertices_range(g)) { diff --git a/src/rose/rose_build_compile.cpp b/src/rose/rose_build_compile.cpp index 96241e39..e24d0b2e 100644 --- a/src/rose/rose_build_compile.cpp +++ b/src/rose/rose_build_compile.cpp @@ -61,10 +61,10 @@ #include "util/compile_context.h" #include "util/container.h" #include "util/dump_charclass.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/order_check.h" #include "util/report_manager.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" #include "util/verify_types.h" @@ -1639,7 +1639,7 @@ static bool danglingVertexRef(RoseBuildImpl &tbi) { RoseGraph::vertex_iterator vi, ve; tie(vi, ve) = vertices(tbi.g); - const ue2::unordered_set valid_vertices(vi, ve); + const unordered_set valid_vertices(vi, ve); if (!contains(valid_vertices, tbi.anchored_root)) { DEBUG_PRINTF("anchored root vertex %zu not in graph\n", diff --git a/src/rose/rose_build_convert.cpp b/src/rose/rose_build_convert.cpp index f80e25cb..33351099 100644 --- a/src/rose/rose_build_convert.cpp +++ b/src/rose/rose_build_convert.cpp @@ -58,8 +58,9 @@ #include #include #include -#include +#include #include +#include #include @@ -561,7 +562,7 @@ bool handleMixedPrefixCliche(const NGHolder &h, RoseGraph &g, RoseVertex v, DEBUG_PRINTF("woot?\n"); shared_ptr h_new = make_shared(); - ue2::unordered_map rhs_map; + unordered_map rhs_map; vector exits_vec; insert(&exits_vec, exits_vec.end(), exits); splitRHS(h, exits_vec, h_new.get(), &rhs_map); diff --git a/src/rose/rose_build_engine_blob.h b/src/rose/rose_build_engine_blob.h index 3aa501b4..da4e355d 100644 --- a/src/rose/rose_build_engine_blob.h +++ b/src/rose/rose_build_engine_blob.h @@ -36,13 +36,14 @@ #include "util/bytecode_ptr.h" #include "util/charreach.h" #include "util/container.h" +#include "util/hash.h" #include "util/multibit_build.h" #include "util/noncopyable.h" -#include "util/ue2_containers.h" #include "util/verify_types.h" +#include "util/unordered.h" -#include #include +#include namespace ue2 { @@ -56,9 +57,10 @@ struct lookaround_info : noncopyable { u32 get_offset_of(const std::vector &look, RoseEngineBlob &blob); private: - unordered_map>, u32> multi_cache; - unordered_map, u32> lcache; - unordered_map, u32> rcache; + using Path = std::vector; + ue2_unordered_map, u32> multi_cache; + ue2_unordered_map, u32> lcache; + ue2_unordered_map rcache; }; class RoseEngineBlob : noncopyable { @@ -160,7 +162,7 @@ private: } /** \brief Cache of previously-written sparse iterators. */ - unordered_map, u32> cached_iters; + ue2_unordered_map, u32> cached_iters; /** * \brief Contents of the Rose bytecode immediately following the diff --git a/src/rose/rose_build_exclusive.cpp b/src/rose/rose_build_exclusive.cpp index e91cc297..25585ec0 100644 --- a/src/rose/rose_build_exclusive.cpp +++ b/src/rose/rose_build_exclusive.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Intel Corporation + * Copyright (c) 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -87,7 +87,7 @@ vector> divideIntoChunks(const RoseBuildImpl &build, /* add prefix literals to engine graph */ static -bool addPrefixLiterals(NGHolder &h, ue2::unordered_set &tailId, +bool addPrefixLiterals(NGHolder &h, unordered_set &tailId, const vector> &triggers) { DEBUG_PRINTF("add literals to graph\n"); @@ -196,8 +196,8 @@ vector findStartPos(const CharReach &cr1, template static bool isExclusive(const NGHolder &h, - const u32 num, ue2::unordered_set &tailId, - map> &skipList, + const u32 num, unordered_set &tailId, + map> &skipList, const RoleInfo &role1, const RoleInfo &role2) { const u32 id1 = role1.id; @@ -253,12 +253,12 @@ bool isExclusive(const NGHolder &h, template static -ue2::unordered_set checkExclusivity(const NGHolder &h, - const u32 num, ue2::unordered_set &tailId, - map> &skipList, - const RoleInfo &role1, - const RoleChunk &roleChunk) { - ue2::unordered_set info; +unordered_set checkExclusivity(const NGHolder &h, + const u32 num, unordered_set &tailId, + map> &skipList, + const RoleInfo &role1, + const RoleChunk &roleChunk) { + unordered_set info; const u32 id1 = role1.id; for (const auto &role2 : roleChunk.roles) { const u32 id2 = role2.id; @@ -316,7 +316,7 @@ void findCliques(const map> &exclusiveGroups, static map> findExclusiveGroups(const RoseBuildImpl &build, - const map> &exclusiveInfo, + const map> &exclusiveInfo, const map> &vertex_map, const bool is_infix) { map> exclusiveGroups; @@ -396,10 +396,10 @@ void exclusiveAnalysis(const RoseBuildImpl &build, vector> &exclusive_roles, const bool is_infix) { const auto &chunks = divideIntoChunks(build, roleInfoSet); DEBUG_PRINTF("Exclusivity analysis entry\n"); - map> exclusiveInfo; + map> exclusiveInfo; for (const auto &roleChunk : chunks) { - map> skipList; + map> skipList; for (const auto &role1 : roleChunk.roles) { const u32 id1 = role1.id; const role_id &s1 = role1.role; diff --git a/src/rose/rose_build_groups.h b/src/rose/rose_build_groups.h index 3ab5eb78..ada64b80 100644 --- a/src/rose/rose_build_groups.h +++ b/src/rose/rose_build_groups.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Intel Corporation + * Copyright (c) 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -35,11 +35,12 @@ #define ROSE_BUILD_GROUPS_H #include "rose_build_impl.h" -#include "util/ue2_containers.h" + +#include namespace ue2 { -unordered_map +std::unordered_map getVertexGroupMap(const RoseBuildImpl &build); rose_group getSquashableGroups(const RoseBuildImpl &build); diff --git a/src/rose/rose_build_impl.h b/src/rose/rose_build_impl.h index 13f1cfc9..42ae054a 100644 --- a/src/rose/rose_build_impl.h +++ b/src/rose/rose_build_impl.h @@ -39,11 +39,12 @@ #include "nfagraph/ng_holder.h" #include "nfagraph/ng_revacc.h" #include "util/bytecode_ptr.h" +#include "util/flat_containers.h" #include "util/hash.h" #include "util/order_check.h" #include "util/queue_index_factory.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" +#include "util/unordered.h" #include "util/verify_types.h" #include @@ -177,7 +178,6 @@ depth findMinWidth(const suffix_id &s); depth findMaxWidth(const suffix_id &s); depth findMinWidth(const suffix_id &s, u32 top); depth findMaxWidth(const suffix_id &s, u32 top); -size_t hash_value(const suffix_id &s); /** \brief represents an engine to the left of a rose role */ struct left_id { @@ -258,11 +258,10 @@ bool isAnchored(const left_id &r); depth findMinWidth(const left_id &r); depth findMaxWidth(const left_id &r); u32 num_tops(const left_id &r); -size_t hash_value(const left_id &r); struct rose_literal_info { - ue2::flat_set delayed_ids; - ue2::flat_set vertices; + flat_set delayed_ids; + flat_set vertices; rose_group group_mask = 0; u32 undelayed_id = MO_INVALID_IDX; bool squash_group = false; @@ -306,6 +305,10 @@ struct rose_literal_id { return s == b.s && msk == b.msk && cmp == b.cmp && table == b.table && delay == b.delay && distinctiveness == b.distinctiveness; } + + size_t hash() const { + return hash_all(s, msk, cmp, table, delay, distinctiveness); + } }; static inline @@ -319,12 +322,6 @@ bool operator<(const rose_literal_id &a, const rose_literal_id &b) { return 0; } -inline -size_t hash_value(const rose_literal_id &lit) { - return hash_all(lit.s, lit.msk, lit.cmp, lit.table, lit.delay, - lit.distinctiveness); -} - class RoseLiteralMap { /** * \brief Main storage for literals. @@ -336,7 +333,7 @@ class RoseLiteralMap { std::deque lits; /** \brief Quick-lookup index from literal -> index in lits. */ - unordered_map lits_index; + ue2_unordered_map lits_index; public: std::pair insert(const rose_literal_id &lit) { @@ -504,7 +501,7 @@ public: // Adds a single literal. void add(bool anchored, bool eod, const ue2_literal &lit, - const ue2::flat_set &ids) override; + const flat_set &ids) override; bool addRose(const RoseInGraph &ig, bool prefilter) override; bool addSombeRose(const RoseInGraph &ig) override; @@ -517,15 +514,15 @@ public: // Returns true if we were able to add it as a mask bool add(bool anchored, const std::vector &mask, - const ue2::flat_set &reports) override; + const flat_set &reports) override; bool addAnchoredAcyclic(const NGHolder &graph) override; bool validateMask(const std::vector &mask, - const ue2::flat_set &reports, bool anchored, + const flat_set &reports, bool anchored, bool eod) const override; void addMask(const std::vector &mask, - const ue2::flat_set &reports, bool anchored, + const flat_set &reports, bool anchored, bool eod) override; // Construct a runtime implementation. @@ -627,8 +624,8 @@ public: * overlap calculation in history assignment. */ std::map anchoredLitSuffix; - unordered_set transient; - unordered_map rose_squash_masks; + ue2_unordered_set transient; + ue2_unordered_map rose_squash_masks; std::vector outfixes; @@ -689,4 +686,22 @@ bool canImplementGraphs(const RoseBuildImpl &tbi); } // namespace ue2 +namespace std { + +template<> +struct hash { + size_t operator()(const ue2::left_id &l) const { + return l.hash(); + } +}; + +template<> +struct hash { + size_t operator()(const ue2::suffix_id &s) const { + return s.hash(); + } +}; + +} // namespace std + #endif /* ROSE_BUILD_IMPL_H */ diff --git a/src/rose/rose_build_infix.cpp b/src/rose/rose_build_infix.cpp index 4bbb3525..80e12542 100644 --- a/src/rose/rose_build_infix.cpp +++ b/src/rose/rose_build_infix.cpp @@ -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: @@ -36,10 +36,12 @@ #include "rose/rose_build_impl.h" #include "util/container.h" #include "util/dump_charclass.h" +#include "util/flat_containers.h" #include "util/graph_range.h" #include "util/graph.h" -#include "util/ue2_containers.h" +#include "util/hash.h" #include "util/ue2string.h" +#include "util/unordered.h" #include #include @@ -51,7 +53,7 @@ namespace ue2 { static bool couldEndLiteral(const ue2_literal &s, NFAVertex initial, const NGHolder &h) { - ue2::flat_set curr, next; + flat_set curr, next; curr.insert(initial); for (auto it = s.rbegin(), ite = s.rend(); it != ite; ++it) { @@ -82,9 +84,10 @@ bool couldEndLiteral(const ue2_literal &s, NFAVertex initial, return true; } +using EdgeCache = ue2_unordered_set>; + static -void contractVertex(NGHolder &g, NFAVertex v, - ue2::unordered_set> &all_edges) { +void contractVertex(NGHolder &g, NFAVertex v, EdgeCache &all_edges) { for (auto u : inv_adjacent_vertices_range(v, g)) { if (u == v) { continue; // self-edge @@ -144,8 +147,9 @@ u32 findMaxLiteralMatches(const NGHolder &h, const set &lits) { cloneHolder(g, h); vector dead; - // The set of all edges in the graph is used for existence checks in contractVertex. - ue2::unordered_set> all_edges; + // The set of all edges in the graph is used for existence checks in + // contractVertex. + EdgeCache all_edges; for (const auto &e : edges_range(g)) { all_edges.emplace(source(e, g), target(e, g)); } diff --git a/src/rose/rose_build_instructions.h b/src/rose/rose_build_instructions.h index 3bc3266b..d3ede29b 100644 --- a/src/rose/rose_build_instructions.h +++ b/src/rose/rose_build_instructions.h @@ -39,6 +39,7 @@ #include "rose_build_lookaround.h" #include "rose_build_program.h" +#include "util/hash.h" #include "util/verify_types.h" namespace ue2 { @@ -65,7 +66,7 @@ public: /** \brief Length of the bytecode instruction in bytes. */ virtual size_t byte_length() const = 0; - using OffsetMap = unordered_map; + using OffsetMap = std::unordered_map; /** * \brief Writes a concrete implementation of this instruction. @@ -149,6 +150,10 @@ private: } }; +template +constexpr RoseInstructionCode + RoseInstrBase::opcode; + /** * \brief Refinement of RoseInstrBase to use for instructions that have * just a single target member, called "target". @@ -190,7 +195,7 @@ public: virtual bool operator==(const RoseInstrType &) const { return true; } size_t hash() const override { - return boost::hash_value(static_cast(Opcode)); + return hash_all(Opcode); } bool equiv_to(const RoseInstrType &, const RoseInstruction::OffsetMap &, @@ -222,7 +227,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), groups, anch_id); + return hash_all(opcode, groups, anch_id); } void write(void *dest, RoseEngineBlob &blob, @@ -251,7 +256,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), min_offset); + return hash_all(opcode, min_offset); } void write(void *dest, RoseEngineBlob &blob, @@ -278,7 +283,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), groups); + return hash_all(opcode, groups); } void write(void *dest, RoseEngineBlob &blob, @@ -305,7 +310,7 @@ public: } size_t hash() const override { - return boost::hash_value(static_cast(opcode)); + return hash_all(opcode); } void write(void *dest, RoseEngineBlob &blob, @@ -335,7 +340,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), min_bound, max_bound); + return hash_all(opcode, min_bound, max_bound); } void write(void *dest, RoseEngineBlob &blob, @@ -364,7 +369,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), key); + return hash_all(opcode, key); } void write(void *dest, RoseEngineBlob &blob, @@ -395,7 +400,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), offset, reach); + return hash_all(opcode, offset, reach); } void write(void *dest, RoseEngineBlob &blob, @@ -426,7 +431,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), look); + return hash_all(opcode, look); } void write(void *dest, RoseEngineBlob &blob, @@ -462,8 +467,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), and_mask, cmp_mask, neg_mask, - offset); + return hash_all(opcode, and_mask, cmp_mask, neg_mask, offset); } void write(void *dest, RoseEngineBlob &blob, @@ -501,8 +505,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), and_mask, cmp_mask, neg_mask, - offset); + return hash_all(opcode, and_mask, cmp_mask, neg_mask, offset); } void write(void *dest, RoseEngineBlob &blob, @@ -539,8 +542,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), and_mask, cmp_mask, negation, - offset); + return hash_all(opcode, and_mask, cmp_mask, negation, offset); } void write(void *dest, RoseEngineBlob &blob, @@ -581,8 +583,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), nib_mask, - bucket_select_mask, neg_mask, offset); + return hash_all(opcode, nib_mask, bucket_select_mask, neg_mask, offset); } void write(void *dest, RoseEngineBlob &blob, @@ -626,8 +627,8 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), hi_mask, lo_mask, - bucket_select_mask, neg_mask, offset); + return hash_all(opcode, hi_mask, lo_mask, bucket_select_mask, neg_mask, + offset); } void write(void *dest, RoseEngineBlob &blob, @@ -671,8 +672,8 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), hi_mask, lo_mask, - bucket_select_mask, neg_mask, offset); + return hash_all(opcode, hi_mask, lo_mask, bucket_select_mask, neg_mask, + offset); } void write(void *dest, RoseEngineBlob &blob, @@ -720,9 +721,8 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), hi_mask, lo_mask, - bucket_select_mask_hi, bucket_select_mask_lo, - neg_mask, offset); + return hash_all(opcode, hi_mask, lo_mask, bucket_select_mask_hi, + bucket_select_mask_lo, neg_mask, offset); } void write(void *dest, RoseEngineBlob &blob, @@ -758,7 +758,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), queue, lag, report); + return hash_all(opcode, queue, lag, report); } void write(void *dest, RoseEngineBlob &blob, @@ -791,7 +791,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), queue, lag, report); + return hash_all(opcode, queue, lag, report); } void write(void *dest, RoseEngineBlob &blob, @@ -820,7 +820,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), delay, index); + return hash_all(opcode, delay, index); } void write(void *dest, RoseEngineBlob &blob, @@ -861,7 +861,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), distance); + return hash_all(opcode, distance); } void write(void *dest, RoseEngineBlob &blob, @@ -889,7 +889,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), queue, lag); + return hash_all(opcode, queue, lag); } void write(void *dest, RoseEngineBlob &blob, @@ -917,7 +917,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), som.type, som.onmatch); + return hash_all(opcode, som.type, som.onmatch); } void write(void *dest, RoseEngineBlob &blob, @@ -953,7 +953,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), cancel, queue, event); + return hash_all(opcode, cancel, queue, event); } void write(void *dest, RoseEngineBlob &blob, @@ -981,7 +981,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), queue, event); + return hash_all(opcode, queue, event); } void write(void *dest, RoseEngineBlob &blob, @@ -1013,8 +1013,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), quash_som, dkey, - offset_adjust); + return hash_all(opcode, quash_som, dkey, offset_adjust); } void write(void *dest, RoseEngineBlob &blob, @@ -1049,8 +1048,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), quash_som, dkey, - offset_adjust); + return hash_all(opcode, quash_som, dkey, offset_adjust); } void write(void *dest, RoseEngineBlob &blob, @@ -1081,7 +1079,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), event, top_squash_distance); + return hash_all(opcode, event, top_squash_distance); } void write(void *dest, RoseEngineBlob &blob, @@ -1110,7 +1108,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), som.type, som.onmatch); + return hash_all(opcode, som.type, som.onmatch); } void write(void *dest, RoseEngineBlob &blob, @@ -1138,7 +1136,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), som.type, som.onmatch); + return hash_all(opcode, som.type, som.onmatch); } void write(void *dest, RoseEngineBlob &blob, @@ -1165,7 +1163,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), onmatch, offset_adjust); + return hash_all(opcode, onmatch, offset_adjust); } void write(void *dest, RoseEngineBlob &blob, @@ -1196,7 +1194,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), onmatch, offset_adjust, ekey); + return hash_all(opcode, onmatch, offset_adjust, ekey); } void write(void *dest, RoseEngineBlob &blob, @@ -1225,7 +1223,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), onmatch, offset_adjust); + return hash_all(opcode, onmatch, offset_adjust); } void write(void *dest, RoseEngineBlob &blob, @@ -1256,7 +1254,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), onmatch, offset_adjust, ekey); + return hash_all(opcode, onmatch, offset_adjust, ekey); } void write(void *dest, RoseEngineBlob &blob, @@ -1293,8 +1291,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), quash_som, dkey, onmatch, - offset_adjust); + return hash_all(opcode, quash_som, dkey, onmatch, offset_adjust); } void write(void *dest, RoseEngineBlob &blob, @@ -1324,7 +1321,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), onmatch, offset_adjust); + return hash_all(opcode, onmatch, offset_adjust); } void write(void *dest, RoseEngineBlob &blob, @@ -1352,7 +1349,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), ekey); + return hash_all(opcode, ekey); } void write(void *dest, RoseEngineBlob &blob, @@ -1384,7 +1381,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), end_adj, min_length); + return hash_all(opcode, end_adj, min_length); } void write(void *dest, RoseEngineBlob &blob, @@ -1410,7 +1407,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), index); + return hash_all(opcode, index); } void write(void *dest, RoseEngineBlob &blob, @@ -1436,7 +1433,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), groups); + return hash_all(opcode, groups); } void write(void *dest, RoseEngineBlob &blob, @@ -1462,7 +1459,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), groups); + return hash_all(opcode, groups); } void write(void *dest, RoseEngineBlob &blob, @@ -1490,7 +1487,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), index); + return hash_all(opcode, index); } void write(void *dest, RoseEngineBlob &blob, @@ -1522,9 +1519,9 @@ public: } size_t hash() const override { - size_t v = hash_all(static_cast(opcode), num_keys); + size_t v = hash_all(opcode, num_keys); for (const u32 &key : jump_table | boost::adaptors::map_keys) { - boost::hash_combine(v, key); + hash_combine(v, key); } return v; } @@ -1594,7 +1591,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), state); + return hash_all(opcode, state); } void write(void *dest, RoseEngineBlob &blob, @@ -1638,7 +1635,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), num_keys, keys); + return hash_all(opcode, num_keys, keys); } void write(void *dest, RoseEngineBlob &blob, @@ -1665,7 +1662,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), iter_offset); + return hash_all(opcode, iter_offset); } void write(void *dest, RoseEngineBlob &blob, @@ -1709,7 +1706,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), literal); + return hash_all(opcode, literal); } void write(void *dest, RoseEngineBlob &blob, @@ -1741,7 +1738,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), literal); + return hash_all(opcode, literal); } void write(void *dest, RoseEngineBlob &blob, @@ -1772,7 +1769,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), literal); + return hash_all(opcode, literal); } void write(void *dest, RoseEngineBlob &blob, @@ -1804,7 +1801,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), literal); + return hash_all(opcode, literal); } void write(void *dest, RoseEngineBlob &blob, @@ -1849,8 +1846,7 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), multi_look, last_start, - start_mask); + return hash_all(opcode, multi_look, last_start, start_mask); } void write(void *dest, RoseEngineBlob &blob, @@ -1905,9 +1901,9 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), nib_mask, - bucket_select_mask, data_select_mask, hi_bits_mask, - lo_bits_mask, neg_mask, base_offset, last_start); + return hash_all(opcode, nib_mask, bucket_select_mask, data_select_mask, + hi_bits_mask, lo_bits_mask, neg_mask, base_offset, + last_start); } void write(void *dest, RoseEngineBlob &blob, @@ -1968,9 +1964,9 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), hi_mask, lo_mask, - bucket_select_mask, data_select_mask, hi_bits_mask, - lo_bits_mask, neg_mask, base_offset, last_start); + return hash_all(opcode, hi_mask, lo_mask, bucket_select_mask, + data_select_mask, hi_bits_mask, lo_bits_mask, neg_mask, + base_offset, last_start); } void write(void *dest, RoseEngineBlob &blob, @@ -2035,10 +2031,9 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), hi_mask, lo_mask, - bucket_select_mask_hi, bucket_select_mask_lo, - data_select_mask, hi_bits_mask, lo_bits_mask, neg_mask, - base_offset, last_start); + return hash_all(opcode, hi_mask, lo_mask, bucket_select_mask_hi, + bucket_select_mask_lo, data_select_mask, hi_bits_mask, + lo_bits_mask, neg_mask, base_offset, last_start); } void write(void *dest, RoseEngineBlob &blob, @@ -2100,9 +2095,9 @@ public: } size_t hash() const override { - return hash_all(static_cast(opcode), hi_mask, lo_mask, - bucket_select_mask, data_select_mask, hi_bits_mask, - lo_bits_mask, neg_mask, base_offset, last_start); + return hash_all(opcode, hi_mask, lo_mask, bucket_select_mask, + data_select_mask, hi_bits_mask, lo_bits_mask, neg_mask, + base_offset, last_start); } void write(void *dest, RoseEngineBlob &blob, diff --git a/src/rose/rose_build_lookaround.cpp b/src/rose/rose_build_lookaround.cpp index a46a1aeb..dd495fd3 100644 --- a/src/rose/rose_build_lookaround.cpp +++ b/src/rose/rose_build_lookaround.cpp @@ -40,7 +40,7 @@ #include "util/container.h" #include "util/dump_charclass.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/verify_types.h" #include @@ -79,7 +79,7 @@ string dump(const map &look) { static void getForwardReach(const NGHolder &g, u32 top, map &look) { - ue2::flat_set curr, next; + flat_set curr, next; // Consider only successors of start with the required top. for (const auto &e : out_edges_range(g.start, g)) { @@ -116,7 +116,7 @@ void getForwardReach(const NGHolder &g, u32 top, map &look) { static void getBackwardReach(const NGHolder &g, ReportID report, u32 lag, map &look) { - ue2::flat_set curr, next; + flat_set curr, next; for (auto v : inv_adjacent_vertices_range(g.accept, g)) { if (contains(g[v].reports, report)) { @@ -187,7 +187,7 @@ void getForwardReach(const raw_dfa &rdfa, map &look) { return; } - ue2::flat_set curr, next; + flat_set curr, next; curr.insert(rdfa.start_anchored); for (u32 i = 0; i < MAX_FWD_LEN && !curr.empty(); i++) { @@ -849,7 +849,7 @@ void mergeLookaround(vector &lookaround, } // Don't merge lookarounds at offsets we already have entries for. - ue2::flat_set offsets; + flat_set offsets; for (const auto &e : lookaround) { offsets.insert(e.offset); } diff --git a/src/rose/rose_build_lookaround.h b/src/rose/rose_build_lookaround.h index aea87ccf..70d4217c 100644 --- a/src/rose/rose_build_lookaround.h +++ b/src/rose/rose_build_lookaround.h @@ -33,6 +33,7 @@ #define ROSE_ROSE_BUILD_LOOKAROUND_H #include "rose_graph.h" +#include "util/hash.h" #include @@ -58,14 +59,6 @@ struct LookEntry { } }; -static inline -size_t hash_value(const LookEntry &l) { - size_t val = 0; - boost::hash_combine(val, l.offset); - boost::hash_combine(val, l.reach); - return val; -} - void findLookaroundMasks(const RoseBuildImpl &tbi, const RoseVertex v, std::vector &look_more); @@ -83,4 +76,15 @@ void mergeLookaround(std::vector &lookaround, } // namespace ue2 +namespace std { + +template<> +struct hash { + size_t operator()(const ue2::LookEntry &l) const { + return ue2::hash_all(l.offset, l.reach); + } +}; + +} // namespace std + #endif // ROSE_ROSE_BUILD_LOOKAROUND_H diff --git a/src/rose/rose_build_merge.cpp b/src/rose/rose_build_merge.cpp index d638e589..15a1ae78 100644 --- a/src/rose/rose_build_merge.cpp +++ b/src/rose/rose_build_merge.cpp @@ -63,9 +63,11 @@ #include "util/container.h" #include "util/dump_charclass.h" #include "util/graph_range.h" +#include "util/hash.h" #include "util/order_check.h" #include "util/report_manager.h" #include "util/ue2string.h" +#include "util/unordered.h" #include #include @@ -77,12 +79,10 @@ #include #include -#include #include using namespace std; using boost::adaptors::map_values; -using boost::hash_combine; namespace ue2 { @@ -336,7 +336,7 @@ void findUncalcLeavesCandidates(RoseBuildImpl &tbi, const RoseGraph &g = tbi.g; vector suffix_vertices; // vertices with suffix graphs - ue2::unordered_map fcount; // ref count per graph + unordered_map fcount; // ref count per graph for (auto v : vertices_range(g)) { if (g[v].suffix) { @@ -566,7 +566,7 @@ bool dedupeLeftfixes(RoseBuildImpl &tbi) { for (deque &verts : roses | map_values) { DEBUG_PRINTF("group has %zu vertices\n", verts.size()); - ue2::unordered_set seen; + unordered_set seen; for (auto jt = verts.begin(), jte = verts.end(); jt != jte; ++jt) { RoseVertex v = *jt; @@ -636,7 +636,7 @@ bool is_equal(const suffix_id &s1, const suffix_id &s2) { void dedupeSuffixes(RoseBuildImpl &tbi) { DEBUG_PRINTF("deduping suffixes\n"); - ue2::unordered_map> suffix_map; + unordered_map> suffix_map; map>, vector> part; // Collect suffixes into groups. @@ -703,7 +703,7 @@ template class Bouquet { private: list ordering; // Unique list in insert order. - typedef ue2::unordered_map > BouquetMap; + using BouquetMap = ue2_unordered_map>; BouquetMap bouquet; public: void insert(const EngineRef &h, RoseVertex v) { @@ -1331,7 +1331,7 @@ bool mergeRosePair(RoseBuildImpl &tbi, left_id &r1, left_id &r2, static void processMergeQueue(RoseBuildImpl &tbi, RoseBouquet &roses, priority_queue &pq) { - ue2::unordered_set dead; + unordered_set dead; DEBUG_PRINTF("merge queue has %zu entries\n", pq.size()); @@ -1862,7 +1862,7 @@ void mergeNfaLeftfixes(RoseBuildImpl &tbi, RoseBouquet &roses) { // We track the number of accelerable states for each graph in a map and // only recompute them when the graph is modified. - ue2::unordered_map accel_count; + unordered_map accel_count; for (const auto &rose : roses) { assert(rose.graph()->kind == NFA_INFIX); accel_count[rose] = estimatedAccelStates(tbi, *rose.graph()); @@ -2157,7 +2157,7 @@ void mergeSuffixes(RoseBuildImpl &tbi, SuffixBouquet &suffixes, // If this isn't an acyclic case, we track the number of accelerable states // for each graph in a map and only recompute them when the graph is // modified. - ue2::unordered_map accel_count; + unordered_map accel_count; if (!acyclic) { for (const auto &suffix : suffixes) { assert(suffix.graph() && suffix.graph()->kind == NFA_SUFFIX); @@ -2499,7 +2499,7 @@ private: template static void pairwiseDfaMerge(vector &dfas, - ue2::unordered_map &dfa_mapping, + unordered_map &dfa_mapping, vector &outfixes, MergeFunctor merge_func) { DEBUG_PRINTF("merging group of size %zu\n", dfas.size()); @@ -2541,7 +2541,7 @@ void pairwiseDfaMerge(vector &dfas, template static void chunkedDfaMerge(vector &dfas, - ue2::unordered_map &dfa_mapping, + unordered_map &dfa_mapping, vector &outfixes, MergeFunctor merge_func) { DEBUG_PRINTF("begin merge of %zu dfas\n", dfas.size()); @@ -2575,7 +2575,7 @@ void mergeOutfixDfas(RoseBuildImpl &tbi, vector &dfas) { /* key is index into outfix array as iterators, etc may be invalidated by * element addition. */ - ue2::unordered_map dfa_mapping; + unordered_map dfa_mapping; for (size_t i = 0; i < outfixes.size(); i++) { auto *rdfa = outfixes[i].rdfa(); if (rdfa) { @@ -2619,7 +2619,7 @@ void mergeOutfixCombo(RoseBuildImpl &tbi, const ReportManager &rm, /* key is index into outfix array as iterators, etc may be invalidated by * element addition. */ size_t new_dfas = 0; - ue2::unordered_map dfa_mapping; + unordered_map dfa_mapping; vector dfas; for (auto it = tbi.outfixes.begin(); it != tbi.outfixes.end(); ++it) { @@ -2670,7 +2670,7 @@ void mergeOutfixHaigs(RoseBuildImpl &tbi, vector &dfas, vector &outfixes = tbi.outfixes; - ue2::unordered_map dfa_mapping; + unordered_map dfa_mapping; for (size_t i = 0; i < outfixes.size(); i++) { auto *haig = outfixes[i].haig(); if (haig) { diff --git a/src/rose/rose_build_misc.cpp b/src/rose/rose_build_misc.cpp index 01be11ef..839fd478 100644 --- a/src/rose/rose_build_misc.cpp +++ b/src/rose/rose_build_misc.cpp @@ -56,11 +56,9 @@ #include "ue2common.h" #include "grey.h" -#include #include using namespace std; -using boost::hash_combine; namespace ue2 { @@ -691,16 +689,7 @@ set all_tops(const suffix_id &s) { } size_t suffix_id::hash() const { - size_t val = 0; - hash_combine(val, g); - hash_combine(val, c); - hash_combine(val, d); - hash_combine(val, h); - return val; -} - -size_t hash_value(const suffix_id &s) { - return s.hash(); + return hash_all(g, c, d, h); } bool isAnchored(const left_id &r) { @@ -761,16 +750,7 @@ u32 num_tops(const left_id &r) { } size_t left_id::hash() const { - size_t val = 0; - hash_combine(val, g); - hash_combine(val, c); - hash_combine(val, d); - hash_combine(val, h); - return val; -} - -size_t hash_value(const left_id &r) { - return r.hash(); + return hash_all(g, c, d, h); } u64a findMaxOffset(const set &reports, const ReportManager &rm) { @@ -997,8 +977,8 @@ bool canImplementGraphs(const RoseBuildImpl &tbi) { bool hasOrphanedTops(const RoseBuildImpl &build) { const RoseGraph &g = build.g; - ue2::unordered_map > roses; - ue2::unordered_map > suffixes; + unordered_map> roses; + unordered_map> suffixes; for (auto v : vertices_range(g)) { if (g[v].left) { diff --git a/src/rose/rose_build_program.cpp b/src/rose/rose_build_program.cpp index 01bd7c54..8f350e29 100644 --- a/src/rose/rose_build_program.cpp +++ b/src/rose/rose_build_program.cpp @@ -41,6 +41,7 @@ #include "util/compile_context.h" #include "util/compile_error.h" #include "util/report_manager.h" +#include "util/unordered.h" #include "util/verify_types.h" #include @@ -226,7 +227,7 @@ size_t RoseProgramHash::operator()(const RoseProgram &program) const { size_t v = 0; for (const auto &ri : program) { assert(ri); - boost::hash_combine(v, ri->hash()); + hash_combine(v, ri->hash()); } return v; } @@ -1934,14 +1935,14 @@ void makeGroupSquashInstruction(const RoseBuildImpl &build, u32 lit_id, namespace { struct ProgKey { - ProgKey(const RoseProgram &p) : prog(&p) { } + ProgKey(const RoseProgram &p) : prog(&p) {} bool operator==(const ProgKey &b) const { return RoseProgramEquivalence()(*prog, *b.prog); } - friend size_t hash_value(const ProgKey &a) { - return RoseProgramHash()(*a.prog); + size_t hash() const { + return RoseProgramHash()(*prog); } private: const RoseProgram *prog; @@ -1954,7 +1955,7 @@ RoseProgram assembleProgramBlocks(vector &&blocks_in) { vector blocks; blocks.reserve(blocks_in.size()); /* to ensure stable reference for seen */ - unordered_set seen; + ue2_unordered_set seen; for (auto &block : blocks_in) { if (contains(seen, block)) { continue; diff --git a/src/rose/rose_build_program.h b/src/rose/rose_build_program.h index afbaa36e..cc59303f 100644 --- a/src/rose/rose_build_program.h +++ b/src/rose/rose_build_program.h @@ -34,8 +34,8 @@ #include "util/bytecode_ptr.h" #include "util/hash.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" +#include #include #include @@ -168,7 +168,7 @@ struct ProgramBuild : noncopyable { /** \brief Mapping from vertex to key, for vertices with a * CHECK_NOT_HANDLED instruction. */ - ue2::unordered_map handledKeys; + std::unordered_map handledKeys; /** \brief Mapping from Rose literal ID to anchored program index. */ std::map anchored_programs; @@ -178,7 +178,7 @@ struct ProgramBuild : noncopyable { /** \brief Mapping from every vertex to the groups that must be on for that * vertex to be reached. */ - ue2::unordered_map vertex_group_map; + std::unordered_map vertex_group_map; /** \brief Global bitmap of groups that can be squashed. */ rose_group squashable_groups = 0; @@ -239,13 +239,13 @@ struct engine_info { RoseProgram assembleProgramBlocks(std::vector &&blocks); RoseProgram makeLiteralProgram(const RoseBuildImpl &build, - const std::map &leftfix_info, - const std::map &suffixes, - const std::map &engine_info_by_queue, - const unordered_map &roleStateIndices, - ProgramBuild &prog_build, u32 lit_id, - const std::vector &lit_edges, - bool is_anchored_replay_program); + const std::map &leftfix_info, + const std::map &suffixes, + const std::map &engine_info_by_queue, + const std::unordered_map &roleStateIndices, + ProgramBuild &prog_build, u32 lit_id, + const std::vector &lit_edges, + bool is_anchored_replay_program); RoseProgram makeDelayRebuildProgram(const RoseBuildImpl &build, ProgramBuild &prog_build, diff --git a/src/rose/rose_build_role_aliasing.cpp b/src/rose/rose_build_role_aliasing.cpp index 0e78ec7d..b5e69ef9 100644 --- a/src/rose/rose_build_role_aliasing.cpp +++ b/src/rose/rose_build_role_aliasing.cpp @@ -45,16 +45,15 @@ #include "util/bitutils.h" #include "util/compile_context.h" #include "util/container.h" +#include "util/flat_containers.h" #include "util/graph.h" #include "util/graph_range.h" #include "util/hash.h" #include "util/order_check.h" -#include "util/ue2_containers.h" #include #include #include -#include #include #include @@ -154,7 +153,7 @@ public: private: /* if a vertex is worth storing, it is worth storing twice */ set main_cont; /* deterministic iterator */ - ue2::unordered_set hash_cont; /* member checks */ + unordered_set hash_cont; /* member checks */ }; struct RoseAliasingInfo { @@ -175,10 +174,10 @@ struct RoseAliasingInfo { } /** \brief Mapping from leftfix to vertices. */ - ue2::unordered_map> rev_leftfix; + unordered_map> rev_leftfix; /** \brief Mapping from undelayed ghost to delayed vertices. */ - ue2::unordered_map> rev_ghost; + unordered_map> rev_ghost; }; } // namespace @@ -787,7 +786,7 @@ void updateEdgeTops(RoseGraph &g, RoseVertex v, const map &top_map) { static void pruneUnusedTops(CastleProto &castle, const RoseGraph &g, const set &verts) { - ue2::unordered_set used_tops; + unordered_set used_tops; for (auto v : verts) { assert(g[v].left.castle.get() == &castle); @@ -818,7 +817,7 @@ void pruneUnusedTops(NGHolder &h, const RoseGraph &g, } assert(isCorrectlyTopped(h)); DEBUG_PRINTF("pruning unused tops\n"); - ue2::flat_set used_tops; + flat_set used_tops; for (auto v : verts) { assert(g[v].left.graph.get() == &h); @@ -1415,7 +1414,7 @@ void removeSingletonBuckets(vector> &buckets) { static void buildInvBucketMap(const vector> &buckets, - ue2::unordered_map &inv) { + unordered_map &inv) { inv.clear(); for (size_t i = 0; i < buckets.size(); i++) { for (auto v : buckets[i]) { @@ -1469,7 +1468,7 @@ void splitByReportSuffixBehaviour(const RoseGraph &g, vector> &buckets) { // Split by report set and suffix info. auto make_split_key = [&g](RoseVertex v) { - return hash_all(g[v].reports, g[v].suffix); + return hash_all(g[v].reports, suffix_id(g[v].suffix)); }; splitAndFilterBuckets(buckets, make_split_key); } @@ -1483,14 +1482,15 @@ void splitByLiteralTable(const RoseBuildImpl &build, auto make_split_key = [&](RoseVertex v) { const auto &lits = g[v].literals; assert(!lits.empty()); - return build.literals.at(*lits.begin()).table; + auto table = build.literals.at(*lits.begin()).table; + return std::underlying_type::type(table); }; splitAndFilterBuckets(buckets, make_split_key); } static void splitByNeighbour(const RoseGraph &g, vector> &buckets, - ue2::unordered_map &inv, bool succ) { + unordered_map &inv, bool succ) { vector> extras; map> neighbours_by_bucket; set picked; @@ -1575,7 +1575,7 @@ splitDiamondMergeBuckets(CandidateSet &candidates, const RoseBuildImpl &build) { } // Neighbour splits require inverse map. - ue2::unordered_map inv; + unordered_map inv; buildInvBucketMap(buckets, inv); splitByNeighbour(g, buckets, inv, true); diff --git a/src/rose/rose_graph.h b/src/rose/rose_graph.h index b7e092bb..d1181063 100644 --- a/src/rose/rose_graph.h +++ b/src/rose/rose_graph.h @@ -43,7 +43,7 @@ #include "nfa/nfa_internal.h" // for MO_INVALID_IDX #include "util/charreach.h" #include "util/depth.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/ue2_graph.h" #include diff --git a/src/rose/rose_in_graph.h b/src/rose/rose_in_graph.h index 42c59932..ed4644ae 100644 --- a/src/rose/rose_in_graph.h +++ b/src/rose/rose_in_graph.h @@ -45,7 +45,7 @@ #include "ue2common.h" #include "rose/rose_common.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include "util/ue2_graph.h" #include "util/ue2string.h" diff --git a/src/rose/rose_in_util.cpp b/src/rose/rose_in_util.cpp index 3b31b38e..9fe47c27 100644 --- a/src/rose/rose_in_util.cpp +++ b/src/rose/rose_in_util.cpp @@ -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: @@ -36,7 +36,6 @@ #include "util/container.h" #include "util/graph_range.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" #include diff --git a/src/som/slot_manager.cpp b/src/som/slot_manager.cpp index 3dc74d3d..d97e8fc1 100644 --- a/src/som/slot_manager.cpp +++ b/src/som/slot_manager.cpp @@ -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 #include -#include - 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 ®ion_map, + const unordered_map ®ion_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 gg = make_shared(); - ue2::unordered_map orig_to_copy; + unordered_map orig_to_copy; cloneHolder(*gg, g, &orig_to_copy); - ue2::unordered_map gg_region_map; + unordered_map 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); diff --git a/src/som/slot_manager.h b/src/som/slot_manager.h index ddb105f5..e5b2d794 100644 --- a/src/som/slot_manager.h +++ b/src/som/slot_manager.h @@ -38,10 +38,10 @@ #include "nfagraph/ng_holder.h" #include "util/bytecode_ptr.h" #include "util/noncopyable.h" -#include "util/ue2_containers.h" #include #include +#include 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 ®ion_map, + const std::unordered_map ®ion_map, u32 last_sent_region, bool *prefix_already_implemented); diff --git a/src/som/slot_manager_internal.h b/src/som/slot_manager_internal.h index 46bfbe83..7e1fecc7 100644 --- a/src/som/slot_manager_internal.h +++ b/src/som/slot_manager_internal.h @@ -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 +#include +#include #include namespace ue2 { @@ -43,14 +44,14 @@ namespace ue2 { struct InitialResetEntry { InitialResetEntry(std::shared_ptr sent_in, std::shared_ptr body_in, - const ue2::unordered_map &body_regions_in, + const std::unordered_map &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 sent; std::shared_ptr body; - ue2::unordered_map body_regions; + std::unordered_map 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 CacheStore; void insert(const NGHolder &prefix, const CharReach &escapes, @@ -96,8 +97,8 @@ struct SlotCache { CacheStore store; - ue2::unordered_set, NGHolderHasher, - NGHolderEqual> initial_prefixes; + std::unordered_set, NGHolderHasher, + NGHolderEqual> initial_prefixes; std::vector initial_resets; }; diff --git a/src/util/accel_scheme.h b/src/util/accel_scheme.h index f524fe93..2a067b30 100644 --- a/src/util/accel_scheme.h +++ b/src/util/accel_scheme.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Intel Corporation + * Copyright (c) 2016-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,7 +30,7 @@ #define ACCEL_SCHEME_H #include "util/charreach.h" -#include "util/ue2_containers.h" +#include "util/flat_containers.h" #include @@ -39,7 +39,7 @@ namespace ue2 { #define MAX_ACCEL_DEPTH 4 struct AccelScheme { - flat_set > double_byte; + flat_set> double_byte; CharReach cr = CharReach::dot(); CharReach double_cr; u32 offset = MAX_ACCEL_DEPTH + 1; diff --git a/src/util/bitfield.h b/src/util/bitfield.h index a71c1f88..24c0c580 100644 --- a/src/util/bitfield.h +++ b/src/util/bitfield.h @@ -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: @@ -36,12 +36,12 @@ #include "ue2common.h" #include "popcount.h" #include "util/bitutils.h" +#include "util/hash.h" #include #include #include -#include namespace ue2 { @@ -373,7 +373,7 @@ public: /// Simple hash. size_t hash() const { - return boost::hash_range(std::begin(bits), std::end(bits)); + return ue2_hasher()(bits); } /// Sentinel value meaning "no more bits", used by find_first and @@ -420,12 +420,17 @@ private: std::array bits; }; -/** \brief Boost-style hash free function. */ -template -size_t hash_value(const bitfield &b) { - return b.hash(); -} - } // namespace ue2 +namespace std { + +template +struct hash> { + size_t operator()(const ue2::bitfield &b) const { + return b.hash(); + } +}; + +} // namespace std + #endif // BITFIELD_H diff --git a/src/util/charreach.h b/src/util/charreach.h index 53f2a5d2..f6d3a2af 100644 --- a/src/util/charreach.h +++ b/src/util/charreach.h @@ -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: @@ -196,12 +196,17 @@ bool isSubsetOf(const CharReach &small, const CharReach &big); bool isutf8ascii(const CharReach &cr); bool isutf8start(const CharReach &cr); -/** \brief Boost-style hash free function. */ -static really_inline -size_t hash_value(const CharReach &cr) { - return cr.hash(); -} - } // namespace ue2 +namespace std { + +template<> +struct hash { + size_t operator()(const ue2::CharReach &cr) const { + return cr.hash(); + } +}; + +} // namespace std + #endif // NG_CHARREACH_H diff --git a/src/util/clique.cpp b/src/util/clique.cpp index 79f06932..c2befea4 100644 --- a/src/util/clique.cpp +++ b/src/util/clique.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, Intel Corporation + * Copyright (c) 2016-2017, Intel Corporation * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -34,7 +34,6 @@ #include "container.h" #include "graph_range.h" #include "make_unique.h" -#include "ue2_containers.h" #include #include diff --git a/src/util/depth.h b/src/util/depth.h index 9af1ded8..5305c6f1 100644 --- a/src/util/depth.h +++ b/src/util/depth.h @@ -221,8 +221,8 @@ public: std::string str() const; #endif - friend size_t hash_value(const depth &d) { - return d.val; + size_t hash() const { + return val; } private: @@ -260,10 +260,6 @@ struct DepthMinMax : totally_ordered { }; -inline size_t hash_value(const DepthMinMax &d) { - return hash_all(d.min, d.max); -} - /** * \brief Merge two DepthMinMax values together to produce their union. */ @@ -271,4 +267,22 @@ DepthMinMax unionDepthMinMax(const DepthMinMax &a, const DepthMinMax &b); } // namespace ue2 +namespace std { + +template<> +struct hash { + size_t operator()(const ue2::depth &d) const { + return d.hash(); + } +}; + +template<> +struct hash { + size_t operator()(const ue2::DepthMinMax &d) const { + return hash_all(d.min, d.max); + } +}; + +} // namespace + #endif // DEPTH_H diff --git a/src/util/ue2_containers.h b/src/util/flat_containers.h similarity index 96% rename from src/util/ue2_containers.h rename to src/util/flat_containers.h index d345a4fa..41452eb4 100644 --- a/src/util/ue2_containers.h +++ b/src/util/flat_containers.h @@ -26,10 +26,11 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef UTIL_UE2_CONTAINERS_H_ -#define UTIL_UE2_CONTAINERS_H_ +#ifndef UTIL_FLAT_CONTAINERS_H +#define UTIL_FLAT_CONTAINERS_H #include "ue2common.h" +#include "util/hash.h" #include "util/operators.h" #include "util/small_vector.h" @@ -38,19 +39,10 @@ #include #include -#include #include -#include -#include namespace ue2 { -/** \brief Unordered set container implemented internally as a hash table. */ -using boost::unordered_set; - -/** \brief Unordered map container implemented internally as a hash table. */ -using boost::unordered_map; - namespace flat_detail { // Iterator facade that wraps an underlying iterator, so that we get our @@ -363,11 +355,6 @@ public: friend void swap(flat_set &a, flat_set &b) { a.swap(b); } - - // Free hash function. - friend size_t hash_value(const flat_set &a) { - return boost::hash_range(a.begin(), a.end()); - } }; /** @@ -652,13 +639,26 @@ public: friend void swap(flat_map &a, flat_map &b) { a.swap(b); } +}; - // Free hash function. - friend size_t hash_value(const flat_map &a) { - return boost::hash_range(a.begin(), a.end()); +} // namespace ue2 + +namespace std { + +template +struct hash> { + size_t operator()(const ue2::flat_set &f) { + return ue2::ue2_hasher()(f); } }; -} // namespace +template +struct hash> { + size_t operator()(const ue2::flat_map &f) { + return ue2::ue2_hasher()(f); + } +}; -#endif // UTIL_UE2_CONTAINERS_H_ +} // namespace std + +#endif // UTIL_FLAT_CONTAINERS_H diff --git a/src/util/graph.h b/src/util/graph.h index 39e86487..9d6bb955 100644 --- a/src/util/graph.h +++ b/src/util/graph.h @@ -35,8 +35,9 @@ #include "container.h" #include "ue2common.h" +#include "util/flat_containers.h" #include "util/graph_range.h" -#include "util/ue2_containers.h" +#include "util/unordered.h" #include #include @@ -115,7 +116,7 @@ bool has_proper_successor(const typename Graph::vertex_descriptor &v, template void find_reachable(const Graph &g, const SourceCont &sources, OutCont *out) { using vertex_descriptor = typename Graph::vertex_descriptor; - ue2::unordered_map colours; + std::unordered_map colours; for (auto v : sources) { boost::depth_first_visit(g, v, @@ -133,7 +134,7 @@ void find_reachable(const Graph &g, const SourceCont &sources, OutCont *out) { template void find_unreachable(const Graph &g, const SourceCont &sources, OutCont *out) { using vertex_descriptor = typename Graph::vertex_descriptor; - ue2::unordered_set reachable; + std::unordered_set reachable; find_reachable(g, sources, &reachable); @@ -182,7 +183,8 @@ find_vertices_in_cycles(const Graph &g) { template bool has_parallel_edge(const Graph &g) { using vertex_descriptor = typename Graph::vertex_descriptor; - ue2::unordered_set> seen; + ue2_unordered_set> seen; + for (const auto &e : edges_range(g)) { auto u = source(e, g); auto v = target(e, g); diff --git a/src/util/hash.h b/src/util/hash.h index 6f76e43d..1c35d20c 100644 --- a/src/util/hash.h +++ b/src/util/hash.h @@ -34,16 +34,126 @@ #ifndef UTIL_HASH_H #define UTIL_HASH_H -#include -#include +#include +#include +#include namespace ue2 { namespace hash_detail { +inline +void hash_combine_impl(size_t &seed, size_t value) { + // Note: constants explicitly truncated on 32-bit platforms. + const size_t a = (size_t)0x0b4e0ef37bc32127ULL; + const size_t b = (size_t)0x318f07b0c8eb9be9ULL; + seed ^= value * a; + seed += b; +} + +/** \brief Helper that determines whether std::begin() exists for T. */ +template +struct is_container_check { +private: + template + static auto has_begin_function(const C &obj) -> decltype(std::begin(obj)) { + return std::begin(obj); + } + static void has_begin_function(...) { + return; + } + using has_begin_type = decltype(has_begin_function(std::declval())); + +public: + static const bool value = !std::is_void::value; +}; + +/** \brief Type trait to enable on whether T is a container. */ +template +struct is_container + : public ::std::integral_constant::value> {}; + +/** \brief Helper that determines whether T::hash() exists. */ +template +struct has_hash_member_check { +private: + template + static auto has_hash_member_function(const C &obj) -> decltype(obj.hash()) { + return obj.hash(); + } + static void has_hash_member_function(...) { + return; + } + using has_hash = decltype(has_hash_member_function(std::declval())); + +public: + static const bool value = !std::is_void::value; +}; + +/** \brief Type trait to enable on whether T::hash() exists. */ +template +struct has_hash_member + : public ::std::integral_constant::value> {}; + +/** \brief Default hash: falls back to std::hash. */ +template +struct ue2_hash { + using decayed_type = typename std::decay::type; + size_t operator()(const T &obj) const { + return std::hash()(obj); + } +}; + +/** \brief Hash for std::pair. */ +template +struct ue2_hash, void> { + size_t operator()(const std::pair &p) const { + size_t v = 0; + hash_combine_impl(v, ue2_hash()(p.first)); + hash_combine_impl(v, ue2_hash()(p.second)); + return v; + } +}; + +/** \brief Hash for any type that has a hash() member function. */ +template +struct ue2_hash::value>::type> { + size_t operator()(const T &obj) const { + return obj.hash(); + } +}; + +/** \brief Hash for any container type that supports std::begin(). */ +template +struct ue2_hash::value && + !has_hash_member::value>::type> { + size_t operator()(const T &obj) const { + size_t v = 0; + for (const auto &elem : obj) { + using element_type = typename std::decay::type; + hash_combine_impl(v, ue2_hash()(elem)); + } + return v; + } +}; + +/** \brief Hash for enum types. */ +template +struct ue2_hash::value>::type> { + size_t operator()(const T &obj) const { + using utype = typename std::underlying_type::type; + return ue2_hash()(static_cast(obj)); + } +}; + +template +void hash_combine(size_t &seed, const T &obj) { + hash_combine_impl(seed, ue2_hash()(obj)); +} + template void hash_build(size_t &v, const T &obj) { - boost::hash_combine(v, obj); + hash_combine(v, obj); } template @@ -54,6 +164,21 @@ void hash_build(size_t &v, const T &obj, Args&&... args) { } // namespace hash_detail +using hash_detail::hash_combine; + +/** + * \brief Hasher for general use. + * + * Provides operators for most standard containers and falls back to + * std::hash. + */ +struct ue2_hasher { + template + size_t operator()(const T &obj) const { + return hash_detail::ue2_hash()(obj); + } +}; + /** * \brief Computes the combined hash of all its arguments. * @@ -70,15 +195,6 @@ size_t hash_all(Args&&... args) { return v; } -/** - * \brief Compute the hash of all the elements of any range on which we can - * call std::begin() and std::end(). - */ -template -size_t hash_range(const Range &r) { - return boost::hash_range(std::begin(r), std::end(r)); -} - } // namespace ue2 #endif // UTIL_HASH_H diff --git a/src/util/hash_dynamic_bitset.h b/src/util/hash_dynamic_bitset.h index 315aed34..65bc29c3 100644 --- a/src/util/hash_dynamic_bitset.h +++ b/src/util/hash_dynamic_bitset.h @@ -34,8 +34,9 @@ #ifndef UTIL_HASH_DYNAMIC_BITSET_H #define UTIL_HASH_DYNAMIC_BITSET_H +#include "hash.h" + #include -#include #include @@ -68,7 +69,7 @@ struct hash_output_it { template void operator=(const T &val) const { - boost::hash_combine(*out, val); + hash_combine(*out, val); } private: diff --git a/src/util/multibit_build.h b/src/util/multibit_build.h index 2d7b5fc2..ba5c8dfa 100644 --- a/src/util/multibit_build.h +++ b/src/util/multibit_build.h @@ -43,10 +43,16 @@ bool operator==(const mmbit_sparse_iter &a, const mmbit_sparse_iter &b) { return a.mask == b.mask && a.val == b.val; } -inline -size_t hash_value(const mmbit_sparse_iter &iter) { - return ue2::hash_all(iter.mask, iter.val); -} +namespace std { + +template<> +struct hash { + size_t operator()(const mmbit_sparse_iter &iter) const { + return ue2::hash_all(iter.mask, iter.val); + } +}; + +} // namespace std namespace ue2 { diff --git a/src/util/partitioned_set.h b/src/util/partitioned_set.h index a9e4644d..41710fe7 100644 --- a/src/util/partitioned_set.h +++ b/src/util/partitioned_set.h @@ -31,7 +31,7 @@ #include "container.h" #include "noncopyable.h" -#include "ue2_containers.h" +#include "flat_containers.h" #include "ue2common.h" #include diff --git a/src/util/report.h b/src/util/report.h index a8e233ff..0d5e69b8 100644 --- a/src/util/report.h +++ b/src/util/report.h @@ -206,13 +206,6 @@ bool operator==(const Report &a, const Report &b) { a.topSquashDistance == b.topSquashDistance; } -inline -size_t hash_value(const Report &r) { - return hash_all(r.type, r.quashSom, r.minOffset, r.maxOffset, r.minLength, - r.ekey, r.offsetAdjust, r.onmatch, r.revNfaIndex, - r.somDistance, r.topSquashDistance); -} - static inline Report makeECallback(u32 report, s32 offsetAdjust, u32 ekey) { Report ir(EXTERNAL_CALLBACK, report); @@ -262,6 +255,19 @@ bool isSimpleExhaustible(const Report &ir) { return true; } -} // namespace +} // namespace ue2 + +namespace std { + +template<> +struct hash { + std::size_t operator()(const ue2::Report &r) const { + return ue2::hash_all(r.type, r.quashSom, r.minOffset, r.maxOffset, + r.minLength, r.ekey, r.offsetAdjust, r.onmatch, + r.revNfaIndex, r.somDistance, r.topSquashDistance); + } +}; + +} // namespace std #endif // UTIL_REPORT_H diff --git a/src/util/report_manager.h b/src/util/report_manager.h index 95e14a2c..aa359ed7 100644 --- a/src/util/report_manager.h +++ b/src/util/report_manager.h @@ -38,10 +38,10 @@ #include "util/compile_error.h" #include "util/noncopyable.h" #include "util/report.h" -#include "util/ue2_containers.h" #include #include +#include #include namespace ue2 { @@ -131,17 +131,17 @@ private: /** \brief Mapping from Report to ID (inverse of \ref reportIds * vector). */ - unordered_map reportIdToInternalMap; + std::unordered_map reportIdToInternalMap; /** \brief Mapping from ReportID to dedupe key. */ - unordered_map reportIdToDedupeKey; + std::unordered_map reportIdToDedupeKey; /** \brief Mapping from ReportID to Rose program offset in bytecode. */ - unordered_map reportIdToProgramOffset; + std::unordered_map reportIdToProgramOffset; /** \brief Mapping from external match ids to information about that * id. */ - unordered_map externalIdMap; + std::unordered_map externalIdMap; /** \brief Mapping from expression index to exhaustion key. */ std::map toExhaustibleKeyMap; diff --git a/src/util/ue2_graph.h b/src/util/ue2_graph.h index 1409e091..bf719fd7 100644 --- a/src/util/ue2_graph.h +++ b/src/util/ue2_graph.h @@ -34,7 +34,6 @@ #include "util/noncopyable.h" #include "util/operators.h" -#include #include /* vertex_index_t, ... */ #include /* no_property */ #include @@ -42,7 +41,9 @@ #include #include +#include /* hash */ #include /* tie */ +#include /* is_same, etc */ #include /* pair, declval */ /* @@ -187,9 +188,8 @@ public: } bool operator==(const vertex_descriptor b) const { return p == b.p; } - friend size_t hash_value(vertex_descriptor v) { - using boost::hash_value; - return hash_value(v.serial); + size_t hash() const { + return std::hash()(serial); } private: @@ -227,9 +227,8 @@ public: } bool operator==(const edge_descriptor b) const { return p == b.p; } - friend size_t hash_value(edge_descriptor e) { - using boost::hash_value; - return hash_value(e.serial); + size_t hash() const { + return std::hash()(serial); } private: @@ -1288,7 +1287,7 @@ edge_index_upper_bound(const Graph &g) { using boost::vertex_index; using boost::edge_index; -} +} // namespace ue2 namespace boost { @@ -1305,5 +1304,29 @@ struct property_map())) const_type; }; -} +} // namespace boost + +namespace std { + +/* Specialization of std::hash so that vertex_descriptor can be used in + * unordered containers. */ +template +struct hash> { + using vertex_descriptor = ue2::graph_detail::vertex_descriptor; + std::size_t operator()(const vertex_descriptor &v) const { + return v.hash(); + } +}; + +/* Specialization of std::hash so that edge_descriptor can be used in + * unordered containers. */ +template +struct hash> { + using edge_descriptor = ue2::graph_detail::edge_descriptor; + std::size_t operator()(const edge_descriptor &e) const { + return e.hash(); + } +}; + +} // namespace std #endif diff --git a/src/util/ue2string.cpp b/src/util/ue2string.cpp index bde975ad..02d7b713 100644 --- a/src/util/ue2string.cpp +++ b/src/util/ue2string.cpp @@ -29,11 +29,14 @@ /** \file * \brief Tools for string manipulation, ue2_literal definition. */ -#include "charreach.h" -#include "compare.h" + #include "ue2string.h" +#include "charreach.h" +#include "compare.h" + #include +#include #include #include #include diff --git a/src/util/ue2string.h b/src/util/ue2string.h index d9fbadcd..9eef65da 100644 --- a/src/util/ue2string.h +++ b/src/util/ue2string.h @@ -208,14 +208,6 @@ private: std::vector nocase; /* for trolling value */ }; -inline -size_t hash_value(const ue2_literal::elem &elem) { - return hash_all(elem.c, elem.nocase); -} - -inline -size_t hash_value(const ue2_literal &lit) { return hash_range(lit); } - /// Return a reversed copy of this literal. ue2_literal reverse_literal(const ue2_literal &in); @@ -314,4 +306,22 @@ std::string escapeString(const ue2_literal &lit); } // namespace ue2 +namespace std { + +template<> +struct hash { + size_t operator()(const ue2::ue2_literal::elem &elem) const { + return ue2::hash_all(elem.c, elem.nocase); + } +}; + +template<> +struct hash { + size_t operator()(const ue2::ue2_literal &lit) const { + return ue2::ue2_hasher()(lit); + } +}; + +} // namespace std + #endif diff --git a/src/util/unordered.h b/src/util/unordered.h new file mode 100644 index 00000000..a8aa61cd --- /dev/null +++ b/src/util/unordered.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, Intel Corporation + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef UTIL_UNORDERED_H +#define UTIL_UNORDERED_H + +/** + * \file + * \brief Unordered set and map containers that default to using our own hasher. + */ + +#include "hash.h" + +#include +#include + +namespace ue2 { + +template +using ue2_unordered_set = std::unordered_set; + +template +using ue2_unordered_map = std::unordered_map; + +} // namespace ue2 + + +#endif // UTIL_UNORDERED_H diff --git a/unit/internal/bitfield.cpp b/unit/internal/bitfield.cpp index e5c5f0ce..40087ef7 100644 --- a/unit/internal/bitfield.cpp +++ b/unit/internal/bitfield.cpp @@ -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 +#include +using namespace std; using namespace ue2; template @@ -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 s; + unordered_set s; s.reserve(size); for (size_t i = 0; i < size; ++i) { diff --git a/unit/internal/depth.cpp b/unit/internal/depth.cpp index ad9ffe38..726aa92c 100644 --- a/unit/internal/depth.cpp +++ b/unit/internal/depth.cpp @@ -29,9 +29,11 @@ #include "config.h" #include "util/depth.h" -#include "util/ue2_containers.h" #include "gtest/gtest.h" +#include + +using namespace std; using namespace ue2; static UNUSED @@ -265,7 +267,7 @@ TEST(depth, u64a_operators) { } TEST(depth, unordered_set) { - ue2::unordered_set depths; + unordered_set depths; for (const auto &val : finite_values) { depths.emplace(val); diff --git a/unit/internal/flat_map.cpp b/unit/internal/flat_map.cpp index 6a81bbfe..610c71e1 100644 --- a/unit/internal/flat_map.cpp +++ b/unit/internal/flat_map.cpp @@ -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 +size_t hash_value(const FlatMap &f) { + return std::hash()(f); +} + TEST(flat_map, hash_value) { const vector> input = { {0, 0}, {3, 1}, {76, 2}, {132, 3}, {77, 4}, {99999, 5}, {100, 6}}; diff --git a/unit/internal/flat_set.cpp b/unit/internal/flat_set.cpp index 3bee0edb..10607a6f 100644 --- a/unit/internal/flat_set.cpp +++ b/unit/internal/flat_set.cpp @@ -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 +size_t hash_value(const FlatSet &f) { + return std::hash()(f); +} + TEST(flat_set, hash_value) { const vector input = {0, 15, 3, 1, 20, 32768, 24000000, 17, 100, 101, 104, 99999}; diff --git a/unit/internal/nfagraph_util.cpp b/unit/internal/nfagraph_util.cpp index b6952f5a..e6a58b55 100644 --- a/unit/internal/nfagraph_util.cpp +++ b/unit/internal/nfagraph_util.cpp @@ -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 lhs_map; - ue2::unordered_map rhs_map; + unordered_map lhs_map; + unordered_map rhs_map; splitGraph(src, pivot, &lhs, &lhs_map, &rhs, &rhs_map); @@ -130,8 +130,8 @@ TEST(NFAGraph, split2) { NFAVertex pivot = c; - ue2::unordered_map lhs_map; - ue2::unordered_map rhs_map; + unordered_map lhs_map; + unordered_map 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 lhs_map; - ue2::unordered_map rhs_map; + unordered_map lhs_map; + unordered_map 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 lhs_map; - ue2::unordered_map rhs_map; + unordered_map lhs_map; + unordered_map rhs_map; splitGraph(src, pivots, &lhs, &lhs_map, &rhs, &rhs_map); diff --git a/unit/internal/rose_build_merge.cpp b/unit/internal/rose_build_merge.cpp index 291c241a..ed7c2bdc 100644 --- a/unit/internal/rose_build_merge.cpp +++ b/unit/internal/rose_build_merge.cpp @@ -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 +#include +#include + +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 seen; + unordered_set seen; for (const auto &v : vertices_range(g)) { if (g[v].suffix) { diff --git a/util/ng_corpus_generator.cpp b/util/ng_corpus_generator.cpp index 19ab7edf..c5fad785 100644 --- a/util/ng_corpus_generator.cpp +++ b/util/ng_corpus_generator.cpp @@ -42,7 +42,6 @@ #include "util/container.h" #include "util/graph_range.h" #include "util/make_unique.h" -#include "util/ue2_containers.h" #include "util/ue2string.h" #include "util/unicode_def.h" #include "util/unicode_set.h" @@ -52,6 +51,7 @@ #include #include #include +#include #include #include @@ -143,7 +143,7 @@ void findPaths(const NGHolder &g, CorpusProperties &cProps, vector> open; open.push_back(ue2::make_unique(1, g.start)); - ue2::unordered_set one_way_in; + unordered_set one_way_in; for (const auto &v : vertices_range(g)) { if (in_degree(v, g) <= 1) { one_way_in.insert(v); diff --git a/util/ng_find_matches.cpp b/util/ng_find_matches.cpp index 97a18375..0a896f73 100644 --- a/util/ng_find_matches.cpp +++ b/util/ng_find_matches.cpp @@ -41,6 +41,7 @@ #include "util/compare.h" #include "util/report.h" #include "util/report_manager.h" +#include "util/unordered.h" #include @@ -770,7 +771,7 @@ struct EdgeCache { } private: - unordered_map, NFAEdge> cache; + ue2_unordered_map, NFAEdge> cache; }; struct fmstate {