Skip to content

Commit

Permalink
Ready to publish to crates.io
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Jul 11, 2024
1 parent 59a4dbe commit ccd03cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ description = "A container that stores numbered objects. Each object can be assi
license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL-2.0"
homepage = "https://github.com/arceos-org/arceos"
repository = "https://github.com/arceos-org/flatten_objects"
documentation = "https://arceos-org.github.io/flatten_objects"
documentation = "https://docs.rs/flatten_objects"
keywords = ["arceos", "data-structures"]
categories = ["no-std", "data-structures"]

[dependencies]
bitmaps = { version = "3.2", default-features = false }
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# flatten_objects

[![Crates.io](https://img.shields.io/crates/v/flatten_objects)](https://crates.io/crates/flatten_objects)

`FlattenObjects` is a container that stores numbered objects.

Objects can be added to the `FlattenObjects`, a unique ID will be assigned
to the object. The ID can be used to retrieve the object later.

# Example

```rust
use flatten_objects::FlattenObjects;

let mut objects = FlattenObjects::<u32, 20>::new();

// Add `23` 10 times and assign them IDs from 0 to 9.
for i in 0..=9 {
objects.add_at(i, 23).unwrap();
assert!(objects.is_assigned(i));
}

// Remove the object with ID 6.
assert_eq!(objects.remove(6), Some(23));
assert!(!objects.is_assigned(6));

// Add `42` (the ID 6 is available now).
let id = objects.add(42).unwrap();
assert_eq!(id, 6);
assert!(objects.is_assigned(id));
assert_eq!(objects.get(id), Some(&42));
assert_eq!(objects.remove(id), Some(42));
assert!(!objects.is_assigned(id));
```

0 comments on commit ccd03cf

Please sign in to comment.