[rust] fast hashmap

December 4, 2019 Leave a comment

In Rust, the stdlib’s HashMap is quite slow. It’s secure, resistant against DOS attacks, but slow. If I write a tool that I want to use myself, it doesn’t have to be cryptographically secure. I want it to be fast.

I tried several alternatives and fxhash proved to be the fastest. I compared the stdlib, hashbrown, ahash and fxhash, and fxhash proved to be the fastest.

In Cargo.toml:

fxhash = "0.2"

In your code:

use fxhash::FxHashMap as HashMap;    // after these renames, it can be used
use fxhash::FxHashSet as HashSet;    // as a drop-in replacement

fn main() {
    let mut map: HashMap = HashMap::default();    // !!! it's called ::default(), not ::new()
    map.insert(1, "one");
    map.insert(2, "two");

    println!("{:?}", map);                  // {2: "two", 1: "one"}
    println!("{}", map.get(&1).unwrap());   // one

I asked on GitHub how to have a fast hashmap in Rust, and the author of hashbrown directed me to these crates. As Amanieu explained, FxHashMap and AHashMap are aliases of the stdlib’s hashmap with custom hashers.

Categories: rust Tags: , , ,

use tmux as a “GUI” interface

November 16, 2019 Leave a comment

I have a console application that clears the screen, draws a table and updates it every second in an infinite loop (let’s call it Part A). If this application is started with a specific command-line parameter, then it starts in interactive mode (Part B). From Part B I can give some commands that control Part A. How could I display both Part A and Part B in the terminal?

You can do it with tmux. With tmuxp, it’s even simpler. Here is a config file called sample.yaml that you can load with “tmuxp load sample.yaml“.

session_name: main-pane-height
- layout: main-horizontal
    main-pane-height: 35
  - shell_command:
    - echo top pane
  - shell_command:
    - echo bottom pane
  window_name: Title Comes Here

This creates two panes and executes the specified commands in the panes. With this I could start Part A in the top pane, and Part B in the bottom pane.

Categories: bash Tags: , , , , ,

htop in full details

November 16, 2019 Leave a comment

See https://peteris.rocks/blog/htop/ for a very detailed explanation of the htop command.

Categories: linux Tags:

crop images easily

November 2, 2019 Leave a comment

You have lots of images and you want to crop them. How to do it without losing your hair?

I just found a nice little hobby project for this: https://github.com/weclaw1/inbac.

Under Manjaro, I had to install tkinter too: “sudo pacman -S tk“.

Reddit discussion here.

Categories: python Tags: , ,

tree command

September 7, 2019 Leave a comment

You want to visualize the tree structure of the current directory.

You need the “tree” command. Under Manjaro it was not installed by default, but of course it could be installed easily with the package manager.

$ tree
├── greetings
│   ├── english.rs
│   └── french.rs
└── lib.rs

1 directory, 3 files

If you want to ignore a subdirectory, use the “-I” option:

$ tree -I target
├── Cargo.lock
├── Cargo.toml
├── src
│   ├── greetings
│   │   ├── english.rs
│   │   └── french.rs
│   └── lib.rs
└── src.old
└── lib.rs

3 directories, 6 files

Categories: linux Tags: , , ,

get system info

August 19, 2019 Leave a comment

To get system info in a simple and readable way, use neofetch:


As I know, it also exists under Ubuntu.

Categories: linux Tags: ,

[manjaro] change window buttons layout

August 18, 2019 Leave a comment

On my desktop I have a Manjaro that I installed years ago. It’s a rolling release distro, meaning I get all the updates, but the graphical interface is not always updated. For instance, I installed a new Manjaro on a laptop, and Manjaro looks much better on my laptop than on my old desktop.
On a newly installed Manjaro, the window buttons are on the right side, but on my desktop they are on the left. How could I unify them and move the buttons to the right?

I found the solution in this video: https://www.youtube.com/watch?v=yVfHDyWcgSA . In short: start the Settings Editor, select xfwm4 on the left, edit “button layout”, and provide the string “O|SHMC” (without quotes).