Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

665 B
Raw Blame
/// Fixed-size list based lookup table, optimized for small positive integer
/// keys.
class FastLookupTable<T> {
  FastLookupTable(Map<int, T> data) {
    var maxIndex = data.keys.first;

    for (var key in data.keys) {
      if (key > maxIndex) {
        maxIndex = key;
      }
    }

    _maxIndex = maxIndex;

    _table = List<T?>.filled(maxIndex + 1, null);

    for (var entry in data.entries) {
      _table[entry.key] = entry.value;
    }
  }

  late final List<T?> _table;
  late final int _maxIndex;

  T? operator [](int index) {
    if (index > _maxIndex) {
      return null;
    }

    return _table[index];
  }

  int get maxIndex => _maxIndex;
}