ProductPromotion
Logo

Elixir

made by https://0x3d.site

GitHub - Cantido/int_set: A time- and memory-efficient data structure for positive integers.
A time- and memory-efficient data structure for positive integers. - Cantido/int_set
Visit Site

GitHub - Cantido/int_set: A time- and memory-efficient data structure for positive integers.

GitHub - Cantido/int_set: A time- and memory-efficient data structure for positive integers.

IntSet

Hex.pm CI

A time- and memory-efficient data structure for positive integers.

Faster than Elixir's MapSet at set operations (union, intersection, difference, equality), and slower at everything else. Also can be serlialized wicked small.

Install

This package can be installed by adding int_set to your list of dependencies in mix.exs:

def deps do
  [
    {:int_set, "~> 1.5"}
  ]
end

The docs can be found at https://hexdocs.pm/int_set.

Usage

Usage is pretty much the same as with MapSet, but you're only allowed to put positive integers (including zero) into the set.

A set can be constructed using IntSet.new/0:

iex> IntSet.new()
IntSet.new([])

An IntSet obeys the same set semantics as MapSet, and provides constant-time operations for insertion, deletion, and membership checking. Use Enum.member?/2 to check for membership.

iex> IntSet.new(3) |> Enum.member?(3)
true

Sets also implement Collectable, so it can collect values in any context that a list can:

iex> Enum.into([1, 2, 3], IntSet.new())
IntSet.new([1, 2, 3])

The inspect/1 implementation for IntSet sorts the members, which makes it way easier to write doctests:

iex> IntSet.new([3, 1, 2])
IntSet.new([1, 2, 3])

Working with applications that use bitstrings becomes way easier, because IntSet.new/1 accepts a bitstring, and IntSet.bitstring/2 can return one.

iex> IntSet.new(5) |> IntSet.bitstring()
<<4>>

iex> IntSet.new(<<0::1, 0::1, 0::1, 0::1, 0::1, 1::1>>)
IntSet.new([5])

This also means that an IntSet can be really efficiently serialized with the use of IntSet.bitstring/2, and IntSet.new/1.

iex> IntSet.new([4, 8, 15, 16, 23, 42]) |> IntSet.bitstring() |> Base.encode16()
"088181000020"
iex> Base.decode16!("088181000020") |> IntSet.new()
IntSet.new([4, 8, 15, 16, 23, 42])

Performance

Check out the iterations-per-second for some operations of MapSet compared to IntSet.

Op MapSet IntSet Comparison
new 4.8K 2.46K 1.95x slower
member? 6.78M 2.93M 2.31x slower
put 4.19M 1.15M 3.66x slower
union 156.4K 944.31K 6.04x faster
difference 48.09 891.27K 18.53x faster
intersection 14.03K 905.70K 64.54x faster
equal? 0.26M 2.41M 9.25x faster

Memory usage is also better for union, difference, intersection, and equality. See the [benchmarks/results] directory for all the benchmarks. You can run the benchmarks for yourself with mix run benchmarks/benchmark.exs.

Maintainer

This project was developed by Rosa Richter. You can get in touch with her on Keybase.io.

Contributing

Questions and pull requests are more than welcome. I follow Elixir's tenet of bad documentation being a bug, so if anything is unclear, please file an issue! Ideally, my answer to your question will be in an update to the docs.

Please see CONTRIBUTING.md for all the details you could ever want about helping me with this project.

Note that this project is released with a Contributor [Code of Conduct]. By participating in this project you agree to abide by its terms.

License

Copyright 2024 Rosa Richter

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Articles
to learn more about the elixir concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here 🔥.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here 🔥.

Queries
or most google FAQ's about Elixir.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory