Code Monkey home page Code Monkey logo

rust-map's Introduction

rust-map

An implementation of a hash map in Rust. For learning purposes only, should not be used in production (for now).

The hash map uses the SipHash algorithm (https://en.wikipedia.org/wiki/SipHash) for hashing the keys.

Usage

Initialization

Create a new hash map with let mut hashmap: CJHashMap<K, V> = CJHashMap::new();, where K and V are the types of the keys and the values.

Ex:

let mut hashmap: CJHashMap<u32, String> = CJHashMap::new();

Adding items

New items can be added with the .set() method.

Ex:

hashmap.set(key, value);

Retrieving values

A value for a stored key can be retrieved with the .get() method.

Ex:

let value = hashmap.get(key);

Removing items

Items can be removed with the .remove() method

Ex:

let removed = hashmap.remove(key);
if removed.is_some() {
  println!("Value of key {key} was removed");
}

The remove() method returns Option<V>. I.e, it returns Some(value) (where "value" is the value of the removed key) if the key was found and removed and None if it wasn't.

Number of items on the map

The length of the map - the number of (key, value) pairs it contains can be retrieved with the .len() method.

Ex:

if hashmap.len() == 0 {
  println!("Map is empty!");
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.