Skip to content

Consider extracting the first limb into a separate field #43

Open
@konsumlamm

Description

@konsumlamm

Currently, BigInt is defined as follows:

type
  BigInt* = object
    limbs: seq[uint32]
    isNegative: bool

It has the invariant that limbs.len >= 1.

It might be worth it changing that to

type
  BigInt* = object
    limbs: seq[uint32]
    first: uint32
    isNegative: bool

This has several advantages:

  • The invariant is now always satisfied (the first limb always exists).
  • Small BigInts require no allocation & pointer indirection.
  • It would avoid special casing 0 (see Empty limbs when uninitialized #26).

Disadvantages:

  • A bit more special handling is needed.
  • The first limb not being next to the other limbs in memory may make a difference (but I doubt it would be noticable).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions