Skip to content

wufangjie/utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My rust utils

data structure

  • [stack, queue, deque] just use `Vec`, `VecDeque` with `match`, `if let`, `while let` to ensure not null.
  • [heap] another implement (std::collections::BinaryHeap)
  • [linkedlist] another implement (std::collections::LinkedList)
  • [avl tree]
  • [red black tree]
  • [trie] TODO: hashmap version?
  • [disjoint set]
  • [segment tree]

macros, structs for debug

dbgt!(&anything)

print debug:

  • file
  • line
  • stringify
  • type
  • value

NOTE: use dbg! if your do not need to know the type!

timeit!

timeit!(100, (0..1000).into_iter().sum::<i32>());
timeit!(10, {
    let mut _sum = 0;
    for i in 0..1000 {
        _sum += i;
    }
});
timeit!(dbg!("hello world!"));

timer

let mut timer = Timer::new()
timer.stop() // print time elapsed from new() to now
timer.diff() // print time elapsed from last stop()/diff() to now

progress bar

ProgressBar

let iter = (0..101).into_iter();
let n = iter.len();
let mut bar = ProgressBar::new(n);
for i in iter {
    bar.goto(i);
    thread::sleep(Duration::from_millis(50));
}
bar.quit();

IterPro

for _ in IterPro::new((0..101).into_iter().take(20)) {
    thread::sleep(Duration::from_millis(50));
}

traits

  • Bisect

Usage (local dependency)

Add dependency in Cargo.toml

[dependencies]
utils = { path = "utils", version = "0.1.0"}

Link or move directory

Recommend link if you only want to keep one copy of the codes

ln -s <real folder> <link folder>

Use in your source code

use utils;

About

my rust utils

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages