GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — async-profiler/src/index.h at jonoffcpu-dev · jonoffcpu/async-profiler Expand file tree/ Copy pathindex.hMore file actions 67 lines (54 loc) · 1.69 KB / Copy pathindex.hFile metadata and controls67 lines (54 loc) · 1.69 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 /* * Copyright The async-profiler authors * SPDX-License-Identifier: Apache-2.0 */ #ifndef _INDEX_H #define _INDEX_H #include <functional> #include <string> #include <unordered_map> #include <vector> #include "arch.h" // Keeps track of values seen and their index of occurrence class Index { private: std::unordered_map<std::string, size_t> _idx_map; size_t _start_index; public: Index(size_t start_index = 0) : _start_index(start_index) { // The first index should contain the empty string indexOf(""); } Index(const Index&) = delete; Index(Index&&) = delete; Index& operator=(const Index&) = delete; Index& operator=(Index&&) = delete; size_t indexOf(const char* value) { return indexOf(std::string(value)); } size_t indexOf(const char* value, size_t len) { return indexOf(std::string(value, len)); } size_t indexOf(const std::string& value) { return _idx_map.insert({value, _start_index + _idx_map.size()}).first->second; } size_t indexOf(std::string&& value) { return _idx_map.insert({std::move(value), _start_index + _idx_map.size()}).first->second; } size_t size() const { return _idx_map.size(); } bool empty() const { return _idx_map.empty(); } void forEachOrdered(const std::function<void(size_t idx, const std::string&)>& consumer) const { std::vector<const std::string*> arr(_idx_map.size()); for (const auto& it : _idx_map) { arr[it.second - _start_index] = &it.first; } for (size_t idx = 0; idx < size(); ++idx) { consumer(idx + _start_index, *arr[idx]); } } }; #endif // _INDEX_H |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |