Skip to content

Why does List<T, N> hold a maximum of N-1 elements? #288

@ikripaka

Description

@ikripaka

While implementing macros for Simplex, I noticed that the List<T, N> type can hold strictly fewer elements than its specified size bound.
For example, if we declare a list with a size limit of 16, it can only hold a maximum of 15 elements.

https://docs.simplicity-lang.org/simplicityhl-reference/type/

"There must be fewer list elements than the bound {bound}"

Partition::Parent { slice, bound } => slice.len() + 1 == bound.get(),

I'm curious about the technical reasoning behind this design choice. Are you inserting the head of the list as the 0th element, resulting in the truncated capacity?
Or a binary tree uses a recursive cutoff, by using 2^i elements in each leaf?
Or is this purely related to how lists are encoded for contract stack execution?

From a developer's perspective, it feels counterintuitive that a list bound of N forces an "off-by-one" capacity limit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions