compact method

  1. @override
List<BigInt> compact(
  1. List<BigInt> hexagons
)
override

Compact a set of hexagons of the same resolution into a set of hexagons across multiple levels that represents the same area.

Implementation

@override
List<BigInt> compact(List<BigInt> hexagons) {
  return using((arena) {
    hexagons = hexagons.toSet().toList(); // remove duplicates
    final hexagonsPointer = arena<Uint64>(hexagons.length);
    for (var i = 0; i < hexagons.length; i++) {
      final pointer = Pointer<Uint64>.fromAddress(
        hexagonsPointer.address + sizeOf<Uint64>() * i,
      );
      pointer.value = hexagons[i].toInt();
    }

    final out = arena<Uint64>(hexagons.length);
    final resultCode = _h3c.compact(hexagonsPointer, out, hexagons.length);
    if (resultCode != 0) {
      throw H3Exception(
        'Failed to compact, malformed input data',
      );
    }
    final list = out.asTypedList(hexagons.length).toList();
    return list.where((e) => e != 0).map((e) => e.toBigInt()).toList();
  });
}