big_array
BigArray
The Array
type in Crystal can only contain Int32::MAX
(2 ** 32 - 1
) elements because it uses 32-bit integers for indexing. This is useful for everyday operations, but sometimes you need to account for larger collections.
Installation
-
Add the dependency to your
shard.yml
:dependencies: big_array: github: jgaskins/big_array
-
Run
shards install
Usage
require "big_array"
Many common operations on Array
are supported, such as Enumerable
and indexing with []
and related methods, but not all operations are supported yet and some methods will return an Array
rather than a BigArray
. PRs are welcome.
array = BigArray{1, 2, 3}
array.each do |i|
puts i
end
You probably don't want to use this in place of an Array
all the time, and probably only for larger amounts of data. Some operations that are handy for small arrays, mostly quality-of-life methods like to_s
and inspect
to show the contents of the array, are not and will not be implemented on BigArray
because you almost certainly don't want to accidentally output billions of objects to your terminal. If you need those methods, you probably don't also need to hold billions of values in the same data structure.
Development
TODO: Write development instructions here
Contributing
- Fork it (https://github.com/jgaskins/big_array/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
- Jamie Gaskins - creator and maintainer
big_array
- 2
- 0
- 0
- 0
- 0
- 2 months ago
- October 11, 2024
MIT License
Fri, 20 Dec 2024 21:23:39 GMT