/src/ntopng/include/FrequentStringItems.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2017-26 - ntop.org |
4 | | * |
5 | | * This program is free software; you can redistribute it and/or modify |
6 | | * it under the terms of the GNU General Public License as published by |
7 | | * the Free Software Foundation; either version 3 of the License, or |
8 | | * (at your option) any later version. |
9 | | * |
10 | | * This program is distributed in the hope that it will be useful, |
11 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | | * GNU General Public License for more details. |
14 | | * |
15 | | * You should have received a copy of the GNU General Public License |
16 | | * along with this program; if not, write to the Free Software Foundation, |
17 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | | * |
19 | | */ |
20 | | |
21 | | #ifndef _FREQUENT_STRING_ITEMS_H_ |
22 | | #define _FREQUENT_STRING_ITEMS_H_ |
23 | | |
24 | | #include "ntop_includes.h" |
25 | | |
26 | | /* https://resources.sei.cmu.edu/asset_files/Presentation/2010_017_001_49763.pdf |
27 | | */ |
28 | | |
29 | | /* *************************************** */ |
30 | | |
31 | | class FrequentStringItems { |
32 | | private: |
33 | | u_int32_t max_items, max_items_threshold; |
34 | | std::map<std::string, u_int32_t> q; |
35 | | Mutex m; |
36 | | bool thread_safe; |
37 | | |
38 | | void prune(); |
39 | | |
40 | | public: |
41 | 22.9k | FrequentStringItems(u_int32_t _max_items, bool _thread_safe = true) { |
42 | 22.9k | max_items = _max_items, max_items_threshold = 2 * _max_items, |
43 | 22.9k | thread_safe = _thread_safe; |
44 | 22.9k | } |
45 | | |
46 | 2 | inline u_int32_t getSize() { return q.size(); }; |
47 | | void add(char* key, u_int32_t value); |
48 | | char* json(u_int32_t max_num_items = (u_int32_t)-1); |
49 | 0 | inline void clear() { q.clear(); } |
50 | | }; |
51 | | |
52 | | #endif /* _FREQUENT_STRING_ITEMS_H_ */ |