From 137c8f5e8a6023db24f90555e968b592a4b843e4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 2 Dec 2017 22:31:42 -0500 Subject: ability to set tag values of enums also remove support for enums with 0 values closes #305 --- src/bigint.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/bigint.cpp') diff --git a/src/bigint.cpp b/src/bigint.cpp index d12c8d0759..f01436d232 100644 --- a/src/bigint.cpp +++ b/src/bigint.cpp @@ -1224,3 +1224,35 @@ Cmp bigint_cmp_zero(const BigInt *op) { } return op->is_negative ? CmpLT : CmpGT; } + +uint32_t bigint_hash(BigInt x) { + if (x.digit_count == 0) { + return 0; + } else { + return bigint_ptr(&x)[0]; + } +} + +bool bigint_eql(BigInt a, BigInt b) { + return bigint_cmp(&a, &b) == CmpEQ; +} + +void bigint_incr(BigInt *x) { + if (x->digit_count == 0) { + bigint_init_unsigned(x, 1); + return; + } + + if (x->digit_count == 1 && x->data.digit != UINT64_MAX) { + x->data.digit += 1; + return; + } + + BigInt copy; + bigint_init_bigint(©, x); + + BigInt one; + bigint_init_unsigned(&one, 1); + + bigint_add(x, ©, &one); +} -- cgit v1.2.3