Skip to content

Commit

Permalink
Remove robin-hood-hashing dependency
Browse files Browse the repository at this point in the history
As per aristocratos#617 using a specialized
hash map/set is not worth the effort
  • Loading branch information
imwints committed Sep 24, 2023
1 parent 2c3ac48 commit b8ce335
Show file tree
Hide file tree
Showing 17 changed files with 133 additions and 2,677 deletions.
2,544 changes: 0 additions & 2,544 deletions include/robin_hood.h

This file was deleted.

4 changes: 3 additions & 1 deletion src/btop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ tab-size = 4
#include <tuple>
#include <regex>
#include <chrono>
#include <unordered_map>
#include <utility>
#ifdef __APPLE__
#include <CoreFoundation/CoreFoundation.h>
#include <mach-o/dyld.h>
Expand Down Expand Up @@ -398,7 +400,7 @@ namespace Runner {
};

string debug_bg;
unordered_flat_map<string, array<uint64_t, 2>> debug_times;
std::unordered_map<string, array<uint64_t, 2>> debug_times;

class MyNumPunct : public std::numpunct<char>
{
Expand Down
13 changes: 7 additions & 6 deletions src/btop_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ tab-size = 4
#include <fstream>
#include <ranges>
#include <string_view>
#include <unordered_map>

#include <fmt/core.h>

Expand Down Expand Up @@ -195,7 +196,7 @@ namespace Config {
"#* The level set includes all lower levels, i.e. \"DEBUG\" will show all logging info."}
};

unordered_flat_map<std::string_view, string> strings = {
std::unordered_map<std::string_view, string> strings = {
{"color_theme", "Default"},
{"shown_boxes", "cpu mem net proc"},
{"graph_symbol", "braille"},
Expand All @@ -221,9 +222,9 @@ namespace Config {
{"proc_command", ""},
{"selected_name", ""},
};
unordered_flat_map<std::string_view, string> stringsTmp;
std::unordered_map<std::string_view, string> stringsTmp;

unordered_flat_map<std::string_view, bool> bools = {
std::unordered_map<std::string_view, bool> bools = {
{"theme_background", true},
{"truecolor", true},
{"rounded_corners", true},
Expand Down Expand Up @@ -269,9 +270,9 @@ namespace Config {
{"show_detailed", false},
{"proc_filtering", false},
};
unordered_flat_map<std::string_view, bool> boolsTmp;
std::unordered_map<std::string_view, bool> boolsTmp;

unordered_flat_map<std::string_view, int> ints = {
std::unordered_map<std::string_view, int> ints = {
{"update_ms", 2000},
{"net_download", 100},
{"net_upload", 100},
Expand All @@ -282,7 +283,7 @@ namespace Config {
{"proc_selected", 0},
{"proc_last_selected", 0},
};
unordered_flat_map<std::string_view, int> intsTmp;
std::unordered_map<std::string_view, int> intsTmp;

bool _locked(const std::string_view name) {
atomic_wait(writelock, true);
Expand Down
17 changes: 8 additions & 9 deletions src/btop_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ tab-size = 4

#pragma once

#include <filesystem>
#include <string>
#include <unordered_map>
#include <vector>
#include <filesystem>

#include <robin_hood.h>

using std::string;
using std::vector;
using robin_hood::unordered_flat_map;

//* Functions and variables for reading and writing the btop config file
namespace Config {

extern std::filesystem::path conf_dir;
extern std::filesystem::path conf_file;

extern unordered_flat_map<std::string_view, string> strings;
extern unordered_flat_map<std::string_view, string> stringsTmp;
extern unordered_flat_map<std::string_view, bool> bools;
extern unordered_flat_map<std::string_view, bool> boolsTmp;
extern unordered_flat_map<std::string_view, int> ints;
extern unordered_flat_map<std::string_view, int> intsTmp;
extern std::unordered_map<std::string_view, string> strings;
extern std::unordered_map<std::string_view, string> stringsTmp;
extern std::unordered_map<std::string_view, bool> bools;
extern std::unordered_map<std::string_view, bool> boolsTmp;
extern std::unordered_map<std::string_view, int> ints;
extern std::unordered_map<std::string_view, int> intsTmp;

const vector<string> valid_graph_symbols = { "braille", "block", "tty" };
const vector<string> valid_graph_symbols_def = { "default", "braille", "block", "tty" };
Expand Down
33 changes: 16 additions & 17 deletions src/btop_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ indent = tab
tab-size = 4
*/

#include <array>
#include <algorithm>
#include <array>
#include <cmath>
#include <ranges>
#include <unordered_map>
#include <utility>

#include "btop_draw.hpp"
#include "btop_config.hpp"
Expand Down Expand Up @@ -51,7 +53,7 @@ namespace Symbols {

const array<string, 10> superscript = { "", "¹", "²", "³", "", "", "", "", "", "" };

const unordered_flat_map<string, vector<string>> graph_symbols = {
const std::unordered_map<string, vector<string>> graph_symbols = {
{ "braille_up", {
" ", "", "", "", "",
"", "", "", "", "",
Expand Down Expand Up @@ -297,7 +299,7 @@ namespace Draw {
return false;
}

static const unordered_flat_map<string, string> clock_custom_format = {
static const std::unordered_map<string, string> clock_custom_format = {
{"/user", Tools::username()},
{"/host", Tools::hostname()},
{"/uptime", ""}
Expand Down Expand Up @@ -605,7 +607,7 @@ namespace Cpu {
static long old_seconds{}; // defaults to = 0
static string old_status;
static Draw::Meter bat_meter {10, "cpu", true};
static const unordered_flat_map<string, string> bat_symbols = {
static const std::unordered_map<string, string> bat_symbols = {
{"charging", ""},
{"discharging", ""},
{"full", ""},
Expand Down Expand Up @@ -749,11 +751,11 @@ namespace Mem {
int disks_io_half = 0;
bool shown = true, redraw = true;
string box;
unordered_flat_map<string, Draw::Meter> mem_meters;
unordered_flat_map<string, Draw::Graph> mem_graphs;
unordered_flat_map<string, Draw::Meter> disk_meters_used;
unordered_flat_map<string, Draw::Meter> disk_meters_free;
unordered_flat_map<string, Draw::Graph> io_graphs;
std::unordered_map<string, Draw::Meter> mem_meters;
std::unordered_map<string, Draw::Graph> mem_graphs;
std::unordered_map<string, Draw::Meter> disk_meters_used;
std::unordered_map<string, Draw::Meter> disk_meters_free;
std::unordered_map<string, Draw::Graph> io_graphs;

string draw(const mem_info& mem, bool force_redraw, bool data_same) {
if (Runner::stopping) return "";
Expand Down Expand Up @@ -801,7 +803,7 @@ namespace Mem {
//? Disk meters and io graphs
if (show_disks) {
if (show_io_stat or io_mode) {
unordered_flat_map<string, int> custom_speeds;
std::unordered_map<string, int> custom_speeds;
int half_height = 0;
if (io_mode) {
disks_io_h = max((int)floor((double)(height - 2 - (disk_ios * 2)) / max(1, disk_ios)), (io_graph_combined ? 1 : 2));
Expand Down Expand Up @@ -1006,7 +1008,7 @@ namespace Net {
int b_x, b_y, b_width, b_height, d_graph_height, u_graph_height;
bool shown = true, redraw = true;
string old_ip;
unordered_flat_map<string, Draw::Graph> graphs;
std::unordered_map<string, Draw::Graph> graphs;
string box;

string draw(const net_info& net, bool force_redraw, bool data_same) {
Expand Down Expand Up @@ -1106,9 +1108,9 @@ namespace Proc {
bool shown = true, redraw = true;
int selected_pid = 0, selected_depth = 0;
string selected_name;
unordered_flat_map<size_t, Draw::Graph> p_graphs;
unordered_flat_map<size_t, bool> p_wide_cmd;
unordered_flat_map<size_t, int> p_counters;
std::unordered_map<size_t, Draw::Graph> p_graphs;
std::unordered_map<size_t, bool> p_wide_cmd;
std::unordered_map<size_t, int> p_counters;
int counter = 0;
Draw::TextEdit filter;
Draw::Graph detailed_cpu_graph;
Expand Down Expand Up @@ -1566,8 +1568,6 @@ namespace Proc {
else
++element;
}
p_graphs.compact();
p_counters.compact();

for (auto element = p_wide_cmd.begin(); element != p_wide_cmd.end();) {
if (rng::find(plist, element->first, &proc_info::pid) == plist.end()) {
Expand All @@ -1576,7 +1576,6 @@ namespace Proc {
else
++element;
}
p_wide_cmd.compact();
}

if (selected == 0 and selected_pid != 0) {
Expand Down
13 changes: 6 additions & 7 deletions src/btop_draw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ tab-size = 4

#pragma once

#include <string>
#include <vector>
#include <array>
#include <robin_hood.h>
#include <deque>
#include <string>
#include <unordered_map>
#include <vector>

using robin_hood::unordered_flat_map;
using std::array;
using std::deque;
using std::string;
Expand Down Expand Up @@ -108,7 +107,7 @@ namespace Draw {
long long offset;
long long last = 0, max_value = 0;
bool current = true, tty_mode = false;
unordered_flat_map<bool, vector<string>> graphs = { {true, {}}, {false, {}}};
std::unordered_map<bool, vector<string>> graphs = { {true, {}}, {false, {}}};

//* Create two representations of the graph to switch between to represent two values for each braille character
void _create(const deque<long long>& data, int data_offset);
Expand All @@ -135,6 +134,6 @@ namespace Draw {

namespace Proc {
extern Draw::TextEdit filter;
extern unordered_flat_map<size_t, Draw::Graph> p_graphs;
extern unordered_flat_map<size_t, int> p_counters;
extern std::unordered_map<size_t, Draw::Graph> p_graphs;
extern std::unordered_map<size_t, int> p_counters;
}
12 changes: 7 additions & 5 deletions src/btop_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ indent = tab
tab-size = 4
*/

#include <csignal>
#include <iostream>
#include <mutex>
#include <ranges>
#include <vector>
#include <thread>
#include <mutex>
#include <signal.h>
#include <unordered_map>
#include <utility>
#include <vector>

#include "btop_input.hpp"
#include "btop_tools.hpp"
Expand All @@ -40,7 +42,7 @@ namespace rng = std::ranges;
namespace Input {

//* Map for translating key codes to readable values
const unordered_flat_map<string, string> Key_escapes = {
const std::unordered_map<string, string> Key_escapes = {
{"\033", "escape"},
{"\n", "enter"},
{" ", "space"},
Expand Down Expand Up @@ -79,7 +81,7 @@ namespace Input {
std::atomic<bool> interrupt (false);
std::atomic<bool> polling (false);
array<int, 2> mouse_pos;
unordered_flat_map<string, Mouse_loc> mouse_mappings;
std::unordered_map<string, Mouse_loc> mouse_mappings;

deque<string> history(50, "");
string old_filter;
Expand Down
9 changes: 4 additions & 5 deletions src/btop_input.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ tab-size = 4

#pragma once

#include <string>
#include <atomic>
#include <array>
#include <robin_hood.h>
#include <atomic>
#include <deque>
#include <string>
#include <unordered_map>

using robin_hood::unordered_flat_map;
using std::array;
using std::atomic;
using std::deque;
Expand All @@ -44,7 +43,7 @@ namespace Input {
};

//? line, col, height, width
extern unordered_flat_map<string, Mouse_loc> mouse_mappings;
extern std::unordered_map<string, Mouse_loc> mouse_mappings;

extern atomic<bool> interrupt;
extern atomic<bool> polling;
Expand Down
12 changes: 5 additions & 7 deletions src/btop_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ indent = tab
tab-size = 4
*/

#include <deque>
#include <robin_hood.h>
#include <array>
#include <signal.h>
#include <errno.h>
#include <cerrno>
#include <cmath>
#include <csignal>
#include <filesystem>
#include <unordered_map>

#include "btop_menu.hpp"
#include "btop_tools.hpp"
Expand All @@ -31,7 +30,6 @@ tab-size = 4
#include "btop_draw.hpp"
#include "btop_shared.hpp"

using robin_hood::unordered_flat_map;
using std::array;
using std::ceil;
using std::max;
Expand Down Expand Up @@ -65,7 +63,7 @@ namespace Menu {
"SIGPWR", "SIGSYS"
};

unordered_flat_map<string, Input::Mouse_loc> mouse_mappings;
std::unordered_map<string, Input::Mouse_loc> mouse_mappings;

const array<array<string, 3>, 3> menu_normal = {
array<string, 3>{
Expand Down Expand Up @@ -1015,7 +1013,7 @@ namespace Menu {
static Draw::TextEdit editor;
static string warnings;
static bitset<8> selPred;
static const unordered_flat_map<string, std::reference_wrapper<const vector<string>>> optionsList = {
static const std::unordered_map<string, std::reference_wrapper<const vector<string>>> optionsList = {
{"color_theme", std::cref(Theme::themes)},
{"log_level", std::cref(Logger::log_levels)},
{"temp_scale", std::cref(Config::temp_scales)},
Expand Down
7 changes: 4 additions & 3 deletions src/btop_menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ tab-size = 4

#pragma once

#include <string>
#include <atomic>
#include <vector>
#include <bitset>
#include <string>
#include <unordered_map>
#include <vector>

#include "btop_input.hpp"

Expand All @@ -38,7 +39,7 @@ namespace Menu {
extern bool redraw;

//? line, col, height, width
extern unordered_flat_map<string, Input::Mouse_loc> mouse_mappings;
extern std::unordered_map<string, Input::Mouse_loc> mouse_mappings;

//* Creates a message box centered on screen
//? Height of box is determined by size of content vector
Expand Down
Loading

0 comments on commit b8ce335

Please sign in to comment.