Skip to content

Add indexes #96

@GGAlanSmithee

Description

@GGAlanSmithee

Indexes

Equivalent of a SQL column index. A new feature which enables the user to add an index to a component, which would - in theory - speed up querying entities with the index.

I am thinking of something in the lines of:

entityManager.createIndex('comp1')
entityManager.createIndex('comp2')

entityManager.getEntititesByComponents('comp1', 'comp2') // sped up, because of indexes

Thoughts on a possible implementation

  1. create per-component indexes (a list of entity ids)
const indexes = {
    'comp1': [ 1, 3, 6, 14, ],
    'comp2': [ 3, 6, 7, 14,  18, ],
    'comp3': [ 6, 14, 25, ],
    'comp4': null,
}
  1. When fetching entities, look for indexes and use them to invalidate entitites (todo: find a fitting algorithm with a low time complexity)

Caveat

It's not unlikely that the additional overhead of indexes would negate any possible wins, in which case a cache-based system would be preferable, (see #79)

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions