Giter Club home page Giter Club logo

rent_vec's Introduction

Rent Vec

The idea behind this crate is to have a vector where each item has its owner, as if it was rented.

Every time you push something into a RentVec it will return you with a lease, and that is one way to access the underlying data.

use rent_vec::RentVec;
let mut vec = RentVec::new();

let mut lease = vec.push(1u32);

let mut item = lease.guard();
*item = 2;

The other way to access data is through the write guard and iterators, that guarantee that no lease is modifying its entry.

let mut guard = vec.guard();
guard.iter();
guard.iter_mut();

If an entry is removed, it will move an item from the back into its location, and mark the other as moved.

let mut lease = vec.push(10u32);
lease.remove();

Once a moved entry is accessed, the lease will become aware of the new location, and the moved entry can be freed.

Why

If you need a StableVec that is as contiguous as possible. The leases are also guaranteed to be valid.

This was written in a morning to figure out what the concept could look like.

Drawbacks

The access performance is worse, since it has to resolve moved entries. After the first resolution, it is O(1).

Push performance is also slower, since it has to search for freed entries amongst moved entries. If there aren't moved entries, it is O(1).

rent_vec's People

Contributors

mateusvmv avatar

Watchers

 avatar

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.