Skip to content

Commit

Permalink
Added changelog, updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ecton committed Jun 21, 2023
1 parent e736d36 commit d2a850a
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .rustme/config.ron
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Configuration(
release: "https://docs.rs/kempt/*/kempt/struct.Map.html",
for_docs: "crate::Map",
),
"set": (
default: "https://khonsulabs.github.io/kempt/main/kempt/struct.Set.html",
release: "https://docs.rs/kempt/*/kempt/struct.Set.html",
for_docs: "crate::Set",
),
"map-merge-with": (
default: "https://khonsulabs.github.io/kempt/main/kempt/struct.Map.html#method.merge_with",
release: "https://docs.rs/kempt/*/kempt/struct.Map.html#method.merge_with",
Expand Down
23 changes: 23 additions & 0 deletions .rustme/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,28 @@ The `HashMap` type is more beneficial for many other use cases:
- Large Key types that are expensive to compare
- Moderately large collections (> 100 entries, depending on Key and Value sizes)

## `Set<T>`

[`Set<T>`][set] provides an interface similar to a `BTreeSet<T>`, but utilizes a
simpler storage model by leveraging this crate's `Map` type. The members are
stored in a `Vec` in sort order. Retrieving values uses a hybrid binary search
and sequential scan algorithm that is aimed at taking advantage of sequential
scans for better cache performance.

```rust
use kempt::Set;

let mut set = Set::new();
set.insert(42);
assert!(set.contains(&42));
// Inserting again will return false, because the member already exists.
assert!(!set.insert(42));
// The collection will be automatically sorted as it is mutated.
set.insert(1);
assert_eq!(set.member(0), Some(&1));
assert_eq!(set.member(1), Some(&42));
```

## Why?

This crate started as a thought experiment: when using [interned
Expand Down Expand Up @@ -128,4 +150,5 @@ their target hardware rather than rely on these benchmark results.
[stylecs]: https://github.com/khonsulabs/stylecs
[fnv]: https://github.com/servo/rust-fnv
[map]: $map$
[set]: $set$
[merge-with]: $map-merge-with$
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- markdownlint-disable MD024 -->
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- `Set<T>` is a new ordered collection type for this crate. It is similar to
BTreeSet, but uses this crate's `Map` type under the hood.
- `Map::insert_with` takes a closure for the value and only invokes the closure
if they key is not found in the collection. If the key is found in the
collection, the map is left unchanged and the key provided to this function is
returned.
- `Map::get_field` returns the `Field` contained within the map, allowing access
to both the Key and value.
- `Map::keys`/`Map::into_keys` return iterators over the keys of a Map.
- `Map::union`/`Map::intersection`/`Map::difference` are new functions that
return iterators that efficiently perform the "set" operations.
- `Field::into_key` takes ownership of the field and returns the owned Key.
- `Field::into_parts` takes ownership of the field and returns a `(Key, Value)`
tuple.
- `Entry::or_default` inserts a default value for the entry if it is vacant. A
mutable reference to the entry's value is returned.
- `VacantEntry::key` returns a reference to the key being inserted.

## v0.1.0

Initial release.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,28 @@ The `HashMap` type is more beneficial for many other use cases:
- Large Key types that are expensive to compare
- Moderately large collections (> 100 entries, depending on Key and Value sizes)

## `Set<T>`

[`Set<T>`][set] provides an interface similar to a `BTreeSet<T>`, but utilizes a
simpler storage model by leveraging this crate's `Map` type. The members are
stored in a `Vec` in sort order. Retrieving values uses a hybrid binary search
and sequential scan algorithm that is aimed at taking advantage of sequential
scans for better cache performance.

```rust
use kempt::Set;

let mut set = Set::new();
set.insert(42);
assert!(set.contains(&42));
// Inserting again will return false, because the member already exists.
assert!(!set.insert(42));
// The collection will be automatically sorted as it is mutated.
set.insert(1);
assert_eq!(set.member(0), Some(&1));
assert_eq!(set.member(1), Some(&42));
```

## Why?

This crate started as a thought experiment: when using [interned
Expand Down Expand Up @@ -130,6 +152,7 @@ their target hardware rather than rely on these benchmark results.
[stylecs]: https://github.com/khonsulabs/stylecs
[fnv]: https://github.com/servo/rust-fnv
[map]: https://khonsulabs.github.io/kempt/main/kempt/struct.Map.html
[set]: https://khonsulabs.github.io/kempt/main/kempt/struct.Set.html
[merge-with]: https://khonsulabs.github.io/kempt/main/kempt/struct.Map.html#method.merge_with

## Open-source Licenses
Expand Down

0 comments on commit d2a850a

Please sign in to comment.