big-types.cr v0.1.1
big-types
Provides data structures that serve as drop-in replacements for Array, Hash, and Set. Unlike the standard types, these structures support sizes that exceed 32-bit indices.
The implementation is based on the Crystal standard library, with 32-bit integers replaced by 64-bit integers.
require "big-types"
x = BigArray(Int32).new # like Array(Int32).new
y = BigSet(Int32).new # like Set(Int32).new
z = BigHash(Int32, Int32).new # like Hash(Int32, Int32).new
Installation
-
Add the dependency to your
shard.yml
:dependencies: big-types: github: philipp-classen/big-types.cr
-
Run
shards install
Usage
require "big-types/big_array"
x = BigArray(Int8).new
4_000_000_000.times { x << 0 }
p! x.size
Note that the equivalent program using standard Array
would have overflowed:
x = Array(Int8).new
4_000_000_000.times { x << 0 }
Unhandled exception: Arithmetic overflow (OverflowError)
from /usr/lib/crystal/int.cr:568:7 in '__crystal_main'
from /usr/lib/crystal/crystal/main.cr:118:5 in 'main'
from /usr/lib/libc.so.6 in '??'
from /usr/lib/libc.so.6 in '__libc_start_main'
from /tmp/phil-crystal-cache-dir/crystal-run-overflow.tmp in '_start'
from ???
The equivalent to Set
is BigSet
:
require "big-types/big_set"
x = BigSet(Int64).new
4_000_000_000.times { |i| x << i }
p! x.size
And, finally, the equivalent to Hash
is BigHash
:
require "big-types/big_hash"
x = BigHash(Int64, Int8).new
4_000_000_000.times { |i| x[i] = 0_i8 }
p! x.size
Development
The code base should stay as close as possible to the implementation in the Crystal standard library.
Contributing
- Fork it (https://github.com/philipp-classen/big-types/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Philipp Claßen - creator and maintainer
Repository
big-types.cr
Owner
Statistic
- 1
- 0
- 0
- 0
- 0
- 5 days ago
- August 18, 2024
License
MIT License
Links
Synced at
Mon, 18 Nov 2024 14:51:18 GMT
Languages