apecs-roaring: Roaring bitmap stores for apecs

[ bsd3, control, data, game, library ] [ Propose Tags ] [ Report a vulnerability ]

Apecs stores for flag-like components backed by CRoaring 64-bit bitmaps.


[Skip to Readme]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 1.0
Change log CHANGELOG.md
Dependencies apecs (>=0.10 && <0.11), base (>=4.18 && <5), croaring-ffi (>=1.0 && <1.1), primitive (>=0.9 && <0.10), vector (>=0.13 && <0.14) [details]
License BSD-3-Clause
Copyright 2026 IC Rainbow
Author IC Rainbow
Maintainer aenor.realm@gmail.com
Uploaded by AlexanderBondarenko at 2026-11-09T15:33:44Z
Revised Revision 1 made by AlexanderBondarenko at 2026-11-10T15:58:18Z
Category Game, Control, Data
Source repo head: git clone https://gitlab.com/dpwiz/apecs-roaring
Distributions
Downloads 3 total (3 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-11-10 [all 3 reports]

Readme for apecs-roaring-1.0

[back to package description]

apecs-roaring

apecs stores for flag-like components and bitmap joins, backed by CRoaring 64-bit bitmaps.

See the benchmark results for how they compare with Map and Cache (tldr: counting, filtering, saving space on large-ish collections).

Usage

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}

import Apecs (Cache, Component (..), Map, cfold, makeWorld, newEntity_, runWith)
import Apecs.Stores.Flags (Flags)
import Apecs.Stores.Roaring (Roaring)
import GHC.Generics (Generic)

data Enemy = Enemy deriving (Generic)

instance Component Enemy where
  type Storage Enemy = Flags Enemy

data Dead = Dead deriving (Generic)

instance Component Dead where
  type Storage Dead = Flags Dead

newtype Health = Health Int

instance Component Health where
  type Storage Health = Roaring (Cache 1024 (Map Health))

makeWorld "World" [''Enemy, ''Dead, ''Health]

main :: IO ()
main = do
  world <- initWorld
  totalHealth <- runWith world $ do
    newEntity_ (Enemy, Health 30)
    newEntity_ (Enemy, Health 10, Dead)
    newEntity_ $ Health 50
    cfold (\total (Health health) -> total + health) 0
  print totalHealth

Query.count from Apecs.Stores.Query reads a store's size off its bitmap without visiting any entity:

enemies <- Query.count @Enemy

Every from the same module joins a tuple by intersecting bitmaps, subtracting any Not terms, and Query.count sizes the join without listing it:

cmap $ \(Every (Enemy, Health health, _ :: Not Dead)) -> Health $ health - 1
livingEnemies <- Query.count @(Every (Enemy, Not Dead))