big-types

Version, currently 0.1.02 versions

github.com/philipp-classen/big-types.cr

Drop-in replacements for Array, Set, and Hash in Crystal, but not limited to 32-bit indexes.

1 stars
0 dependents
License: MIT

Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.

Installation

# Add this to your shard.yml
dependencies:
  big-types:
    github: philipp-classen/big-types.cr
    version: ~> 0.1.0

Then run:

shards install

shard.yml

No shard.yml has been indexed for 0.1.0. You can read it on the repository.

Dependencies

Unknown: the shard.yml for this version has not been read yet.

README

This README is the one indexed from the repository at its latest ref, not from the tag for this version.

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

  1. Add the dependency to your shard.yml:

    dependencies:
      big-types:
        github: philipp-classen/big-types.cr
  2. 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

  1. Fork it (https://github.com/philipp-classen/big-types/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors