{
  "slug": "rank-select",
  "term": "Rank/select",
  "aliases": [
    "Bitvector rank and select",
    "Rank/select dictionary"
  ],
  "definition": "Rank counts selected bits in a bitvector prefix, while select locates a selected bit by its occurrence number.",
  "note": "Contract: With zero-based bit positions, R(p) counts ones before p, for 0 <= p <= n. S(j) returns the position of one number j, with occurrences numbered from zero. For valid j, R(S(j)) = j and R(S(j) + 1) = j + 1. These are different coordinate systems, not interchangeable offsets. [broadword]\n\nExample: In 10010110, one positions are 0, 3, 5, 6. Thus R(3) = 1, S(1) = 3, and the number of ones in positions 3 through 5 is R(6) - R(3) = 2. Empty prefixes are valid; selecting a nonexistent one is outside the operation's domain. [example]\n\nConventions: SDSL rank excludes its endpoint but select numbers occurrences from one; its second one is select(2) = 3 in the example. SuRF's section 2.6 rank example includes the queried bit. Translate that inclusive rank at p as R(p + 1), not R(p). A formula copied without its endpoint and ordinal conventions can silently address the wrong entry. [sdsl] [surf]\n\nStorage: Efficient queries require support structures as well as the bitmap. Vigna's rank9 stores two 64-bit support words per 512 data bits, a 25% layout overhead before boundary handling. The SuRF sparse trie's 10 bits per node likewise excludes auxiliary rank/select bits. Neither figure is a whole-index memory bill. [broadword] [surf]",
  "related": [
    "succinct-data-structure",
    "rrr-bitvector",
    "elias-fano",
    "succinct-range-filter",
    "wavelet-tree",
    "wavelet-matrix",
    "fm-index"
  ],
  "citations": [
    {
      "id": "broadword",
      "title": "Sebastiano Vigna, Broadword Implementation of Rank/Select Queries, author revision 2023-01-31, sections 2-3",
      "url": "https://vigna.di.unimi.it/ftp/papers/Broadword.pdf",
      "accessed": "2026-11-17"
    },
    {
      "id": "sdsl",
      "title": "SDSL tutorial: rank_support and select_support examples",
      "url": "https://simongog.github.io/assets/data/sdsl-slides/tutorial",
      "accessed": "2026-11-17"
    },
    {
      "id": "surf",
      "title": "Zhang et al., SuRF: Practical Range Query Filtering with Fast Succinct Tries, SIGMOD 2018, sections 2.5-2.6",
      "url": "https://db.cs.cmu.edu/papers/2018/mod601-zhangA-hm.pdf",
      "accessed": "2026-11-17"
    },
    {
      "id": "example",
      "title": "Hesela: rank/select convention examples and exact scanning reference (CC0)",
      "url": "https://hesela.dev/research/rank-select.mjs",
      "accessed": "2026-11-17"
    },
    {
      "id": "tests",
      "title": "Hesela: exhaustive rank/select identities and invalid-input tests (CC0)",
      "url": "https://hesela.dev/research/rank-select.test.mjs",
      "accessed": "2026-11-17"
    }
  ],
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-17",
  "provenance": [
    "Primary-source synthesis of indexing conventions and memory accounting, not a replication of throughput experiments.",
    "The worked bitvector is constructed. Its downloadable reference scans bits and is not a succinct rank/select implementation.",
    "The Broadword PDF identifies itself as the 2023-01-31 author revision; this is not a claim that the underlying work was first published in 2023."
  ]
}
