diff options
author | gatecat <gatecat@ds0.me> | 2021-06-03 09:04:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 09:04:34 +0100 |
commit | a3d8b4f9d198226ec0903e34a8d290b376b45c0b (patch) | |
tree | ada2c6a5d48e766fa523e633aaa28179baea3273 /common/util.h | |
parent | 589ca8ded5da2012e4388a3ec4c8fae74dff75e4 (diff) | |
parent | dcbb322447a7fb59cabe197ec1dd2307acfa3681 (diff) | |
download | nextpnr-a3d8b4f9d198226ec0903e34a8d290b376b45c0b.tar.gz nextpnr-a3d8b4f9d198226ec0903e34a8d290b376b45c0b.tar.bz2 nextpnr-a3d8b4f9d198226ec0903e34a8d290b376b45c0b.zip |
Merge pull request #718 from YosysHQ/gatecat/hashlib
Moving from unordered_{map, set} to hashlib
Diffstat (limited to 'common/util.h')
-rw-r--r-- | common/util.h | 41 |
1 files changed, 2 insertions, 39 deletions
diff --git a/common/util.h b/common/util.h index 540646c7..542bd395 100644 --- a/common/util.h +++ b/common/util.h @@ -55,7 +55,7 @@ std::string str_or_default(const Container &ct, const KeyType &key, std::string }; template <typename KeyType> -std::string str_or_default(const std::unordered_map<KeyType, Property> &ct, const KeyType &key, std::string def = "") +std::string str_or_default(const dict<KeyType, Property> &ct, const KeyType &key, std::string def = "") { auto found = ct.find(key); if (found == ct.end()) @@ -78,8 +78,7 @@ template <typename Container, typename KeyType> int int_or_default(const Contain return std::stoi(found->second); }; -template <typename KeyType> -int int_or_default(const std::unordered_map<KeyType, Property> &ct, const KeyType &key, int def = 0) +template <typename KeyType> int int_or_default(const dict<KeyType, Property> &ct, const KeyType &key, int def = 0) { auto found = ct.find(key); if (found == ct.end()) @@ -103,42 +102,6 @@ bool bool_or_default(const Container &ct, const KeyType &key, bool def = false) return bool(int_or_default(ct, key, int(def))); }; -// Wrap an unordered_map, and allow it to be iterated over sorted by key -template <typename K, typename V> std::map<K, V *> sorted(const std::unordered_map<K, std::unique_ptr<V>> &orig) -{ - std::map<K, V *> retVal; - for (auto &item : orig) - retVal.emplace(std::make_pair(item.first, item.second.get())); - return retVal; -}; - -// Wrap an unordered_map, and allow it to be iterated over sorted by key -template <typename K, typename V> std::map<K, V &> sorted_ref(std::unordered_map<K, V> &orig) -{ - std::map<K, V &> retVal; - for (auto &item : orig) - retVal.emplace(std::make_pair(item.first, std::ref(item.second))); - return retVal; -}; - -// Wrap an unordered_map, and allow it to be iterated over sorted by key -template <typename K, typename V> std::map<K, const V &> sorted_cref(const std::unordered_map<K, V> &orig) -{ - std::map<K, const V &> retVal; - for (auto &item : orig) - retVal.emplace(std::make_pair(item.first, std::ref(item.second))); - return retVal; -}; - -// Wrap an unordered_set, and allow it to be iterated over sorted by key -template <typename K> std::set<K> sorted(const std::unordered_set<K> &orig) -{ - std::set<K> retVal; - for (auto &item : orig) - retVal.insert(item); - return retVal; -}; - // Return a net if port exists, or nullptr inline const NetInfo *get_net_or_empty(const CellInfo *cell, const IdString port) { |