@woosh/meep-engine 2.138.19 → 2.139.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/core/collection/PairUint32Map.d.ts +100 -0
- package/src/core/collection/PairUint32Map.d.ts.map +1 -0
- package/src/core/collection/PairUint32Map.js +321 -0
- package/src/core/collection/Uint32Map.d.ts +119 -0
- package/src/core/collection/Uint32Map.d.ts.map +1 -0
- package/src/core/collection/Uint32Map.js +345 -0
- package/src/core/collection/array/array_shuffle.d.ts +10 -3
- package/src/core/collection/array/array_shuffle.d.ts.map +1 -1
- package/src/core/collection/array/array_shuffle.js +27 -22
- package/src/core/collection/heap/FibonacciHeap.d.ts +195 -0
- package/src/core/collection/heap/FibonacciHeap.d.ts.map +1 -0
- package/src/core/collection/heap/FibonacciHeap.js +586 -0
- package/src/core/collection/heap/Uint32Heap.js +1 -1
- package/src/core/collection/heap/Uint32Heap4.d.ts +169 -0
- package/src/core/collection/heap/Uint32Heap4.d.ts.map +1 -0
- package/src/core/collection/heap/Uint32Heap4.js +490 -0
- package/src/core/geom/3d/line/line3_closest_points_segment_segment.d.ts +27 -0
- package/src/core/geom/3d/line/line3_closest_points_segment_segment.d.ts.map +1 -0
- package/src/core/geom/3d/line/line3_closest_points_segment_segment.js +88 -0
- package/src/core/geom/3d/shape/BoxShape3D.d.ts +61 -0
- package/src/core/geom/3d/shape/BoxShape3D.d.ts.map +1 -0
- package/src/core/geom/3d/shape/BoxShape3D.js +158 -0
- package/src/core/geom/3d/shape/CapsuleShape3D.d.ts +11 -0
- package/src/core/geom/3d/shape/CapsuleShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/CapsuleShape3D.js +12 -0
- package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts +37 -9
- package/src/core/geom/3d/shape/UnitCubeShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitCubeShape3D.js +45 -98
- package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts +10 -0
- package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitSphereShape3D.js +11 -0
- package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.d.ts +61 -0
- package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.d.ts.map +1 -0
- package/src/core/geom/3d/shape/util/shape3d_voxelize_to_grid.js +148 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.d.ts +39 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedral_mesh_from_surface.js +147 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.d.ts +15 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/compute_tetrahedron_quality.js +22 -0
- package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.d.ts +2 -0
- package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/prototype_tetrahedrize_mesh.js +673 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts +26 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_carve_outside_surface.js +222 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.d.ts +34 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_find_tets_around_edge.js +146 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.d.ts +36 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_23.js +232 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.d.ts +33 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_flip_32.js +255 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts +68 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_improve_quality.js +365 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts +31 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_smooth_vertex.js +112 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts +22 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedral_mesh_vertex_is_boundary.js +55 -0
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.d.ts +32 -0
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.d.ts.map +1 -0
- package/src/core/geom/3d/tetrahedra/tetrahedron_compute_quality.js +66 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts +22 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/BinaryElementPool.js +49 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.d.ts +134 -0
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/BinaryTopology.js +276 -3
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts +17 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.js +135 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.d.ts +14 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compact.js +177 -0
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_decouple.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_decouple.js +20 -4
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.js +5 -3
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_create.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_create.js +9 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_get_or_create.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_get_or_create.js +21 -45
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill.js +7 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts +8 -6
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.js +8 -6
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.d.ts +22 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_kill_short_edges.js +73 -0
- package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vertex_replace.d.ts.map +1 -1
- package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vertex_replace.js +51 -1
- package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.d.ts +10 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_edge_get.js +42 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts +28 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_sample_interior_grid_points.js +227 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.d.ts +13 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_walk_boundary_loops.js +108 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.d.ts +11 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.d.ts.map +1 -0
- package/src/core/geom/3d/topology/struct/binary/query/bt_query_edge_is_boundary.js +20 -0
- package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.d.ts +20 -0
- package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.d.ts.map +1 -0
- package/src/core/geom/3d/triangle/triangle_mesh_compute_signed_volume.js +38 -0
- package/src/core/graph/csr/CSRGraph.d.ts +168 -0
- package/src/core/graph/csr/CSRGraph.d.ts.map +1 -0
- package/src/core/graph/csr/CSRGraph.js +319 -0
- package/src/core/graph/metis/cluster_mesh_metis.d.ts +12 -0
- package/src/core/graph/metis/cluster_mesh_metis.d.ts.map +1 -1
- package/src/core/graph/metis/cluster_mesh_metis.js +12 -0
- package/src/core/graph/metis/metis.d.ts +19 -0
- package/src/core/graph/metis/metis.d.ts.map +1 -1
- package/src/core/graph/metis/metis.js +20 -0
- package/src/core/graph/metis/metis_cluster_bs.d.ts +11 -0
- package/src/core/graph/metis/metis_cluster_bs.d.ts.map +1 -1
- package/src/core/graph/metis/metis_cluster_bs.js +11 -0
- package/src/core/graph/metis/metis_options.d.ts +17 -2
- package/src/core/graph/metis/metis_options.d.ts.map +1 -1
- package/src/core/graph/metis/metis_options.js +17 -2
- package/src/core/graph/metis/native/MetisGraph.d.ts +144 -0
- package/src/core/graph/metis/native/MetisGraph.d.ts.map +1 -0
- package/src/core/graph/metis/native/MetisGraph.js +212 -0
- package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts +72 -0
- package/src/core/graph/metis/native/bisection/BisectionScratch.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/BisectionScratch.js +101 -0
- package/src/core/graph/metis/native/bisection/bisect_graph.d.ts +37 -0
- package/src/core/graph/metis/native/bisection/bisect_graph.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/bisect_graph.js +100 -0
- package/src/core/graph/metis/native/bisection/compute_2way_params.d.ts +15 -0
- package/src/core/graph/metis/native/bisection/compute_2way_params.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/compute_2way_params.js +84 -0
- package/src/core/graph/metis/native/bisection/fm_2way.d.ts +30 -0
- package/src/core/graph/metis/native/bisection/fm_2way.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/fm_2way.js +290 -0
- package/src/core/graph/metis/native/bisection/grow_bisection.d.ts +23 -0
- package/src/core/graph/metis/native/bisection/grow_bisection.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/grow_bisection.js +137 -0
- package/src/core/graph/metis/native/bisection/split_graph_two_way.d.ts +28 -0
- package/src/core/graph/metis/native/bisection/split_graph_two_way.d.ts.map +1 -0
- package/src/core/graph/metis/native/bisection/split_graph_two_way.js +119 -0
- package/src/core/graph/metis/native/coarsen/coarsen_graph.d.ts +20 -0
- package/src/core/graph/metis/native/coarsen/coarsen_graph.d.ts.map +1 -0
- package/src/core/graph/metis/native/coarsen/coarsen_graph.js +94 -0
- package/src/core/graph/metis/native/coarsen/create_coarse_graph.d.ts +24 -0
- package/src/core/graph/metis/native/coarsen/create_coarse_graph.d.ts.map +1 -0
- package/src/core/graph/metis/native/coarsen/create_coarse_graph.js +158 -0
- package/src/core/graph/metis/native/coarsen/match_shem.d.ts +41 -0
- package/src/core/graph/metis/native/coarsen/match_shem.d.ts.map +1 -0
- package/src/core/graph/metis/native/coarsen/match_shem.js +175 -0
- package/src/core/graph/metis/native/initial/initial_kway_bfs.d.ts +24 -0
- package/src/core/graph/metis/native/initial/initial_kway_bfs.d.ts.map +1 -0
- package/src/core/graph/metis/native/initial/initial_kway_bfs.js +122 -0
- package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.d.ts +29 -0
- package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.d.ts.map +1 -0
- package/src/core/graph/metis/native/initial/initial_kway_recursive_bisection.js +170 -0
- package/src/core/graph/metis/native/metis_partition_kway.d.ts +41 -0
- package/src/core/graph/metis/native/metis_partition_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/metis_partition_kway.js +126 -0
- package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.d.ts +62 -0
- package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/IndexedFloatMaxHeap.js +261 -0
- package/src/core/graph/metis/native/refine/RefinementScratch.d.ts +45 -0
- package/src/core/graph/metis/native/refine/RefinementScratch.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/RefinementScratch.js +53 -0
- package/src/core/graph/metis/native/refine/compute_kway_params.d.ts +18 -0
- package/src/core/graph/metis/native/refine/compute_kway_params.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/compute_kway_params.js +138 -0
- package/src/core/graph/metis/native/refine/fm_kway.d.ts +63 -0
- package/src/core/graph/metis/native/refine/fm_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/fm_kway.js +462 -0
- package/src/core/graph/metis/native/refine/project_kway.d.ts +22 -0
- package/src/core/graph/metis/native/refine/project_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/project_kway.js +43 -0
- package/src/core/graph/metis/native/refine/refine_kway.d.ts +34 -0
- package/src/core/graph/metis/native/refine/refine_kway.d.ts.map +1 -0
- package/src/core/graph/metis/native/refine/refine_kway.js +43 -0
- package/src/core/math/linalg/eigen/matrix_householder_in_place.d.ts +2 -2
- package/src/core/math/linalg/eigen/matrix_householder_in_place.js +2 -2
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts +6 -4
- package/src/core/math/linalg/eigen/matrix_qr_in_place.d.ts.map +1 -1
- package/src/core/math/linalg/eigen/matrix_qr_in_place.js +69 -23
- package/src/engine/EngineHarness.d.ts +3 -1
- package/src/engine/EngineHarness.d.ts.map +1 -1
- package/src/engine/EngineHarness.js +6 -4
- package/src/engine/control/first-person/DESIGN.md +30 -6
- package/src/engine/control/first-person/DESIGN_EXTENSIONS.md +563 -0
- package/src/engine/control/first-person/FirstPersonPlayerController.d.ts +102 -9
- package/src/engine/control/first-person/FirstPersonPlayerController.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerController.js +38 -3
- package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts +533 -4
- package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerControllerConfig.js +315 -6
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts +220 -22
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.d.ts.map +1 -1
- package/src/engine/control/first-person/FirstPersonPlayerControllerSystem.js +858 -241
- package/src/engine/control/first-person/TODO.md +127 -0
- package/src/engine/control/first-person/abilities/Ability.d.ts +101 -0
- package/src/engine/control/first-person/abilities/Ability.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/Ability.js +119 -0
- package/src/engine/control/first-person/abilities/AbilitySet.d.ts +86 -0
- package/src/engine/control/first-person/abilities/AbilitySet.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/AbilitySet.js +185 -0
- package/src/engine/control/first-person/abilities/LedgeGrab.d.ts +62 -0
- package/src/engine/control/first-person/abilities/LedgeGrab.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/LedgeGrab.js +199 -0
- package/src/engine/control/first-person/abilities/Mantle.d.ts +45 -0
- package/src/engine/control/first-person/abilities/Mantle.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/Mantle.js +188 -0
- package/src/engine/control/first-person/abilities/Slide.d.ts +33 -0
- package/src/engine/control/first-person/abilities/Slide.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/Slide.js +158 -0
- package/src/engine/control/first-person/abilities/WallJump.d.ts +45 -0
- package/src/engine/control/first-person/abilities/WallJump.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/WallJump.js +131 -0
- package/src/engine/control/first-person/abilities/WallRun.d.ts +44 -0
- package/src/engine/control/first-person/abilities/WallRun.d.ts.map +1 -0
- package/src/engine/control/first-person/abilities/WallRun.js +180 -0
- package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts +49 -0
- package/src/engine/control/first-person/composer/EyeOffsetStack.d.ts.map +1 -0
- package/src/engine/control/first-person/composer/EyeOffsetStack.js +60 -0
- package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts +100 -0
- package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/BreathRhythmEvaluator.js +133 -0
- package/src/engine/control/first-person/mastery/DecisionPoint.d.ts +10 -0
- package/src/engine/control/first-person/mastery/DecisionPoint.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/DecisionPoint.js +30 -0
- package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts +61 -0
- package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/FootAsymmetryTurnEvaluator.js +109 -0
- package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts +40 -0
- package/src/engine/control/first-person/mastery/MasteryEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/MasteryEvaluator.js +45 -0
- package/src/engine/control/first-person/mastery/MasteryScore.d.ts +68 -0
- package/src/engine/control/first-person/mastery/MasteryScore.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/MasteryScore.js +100 -0
- package/src/engine/control/first-person/mastery/MasterySet.d.ts +60 -0
- package/src/engine/control/first-person/mastery/MasterySet.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/MasterySet.js +86 -0
- package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts +58 -0
- package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/SlideInitiationTimingEvaluator.js +83 -0
- package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts +69 -0
- package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.d.ts.map +1 -0
- package/src/engine/control/first-person/mastery/StrideTimingJumpEvaluator.js +109 -0
- package/src/engine/control/first-person/math/Spring.d.ts +56 -0
- package/src/engine/control/first-person/math/Spring.d.ts.map +1 -0
- package/src/engine/control/first-person/math/Spring.js +71 -0
- package/src/engine/control/first-person/math/computeLRCBreathRate.d.ts +26 -0
- package/src/engine/control/first-person/math/computeLRCBreathRate.d.ts.map +1 -0
- package/src/engine/control/first-person/math/computeLRCBreathRate.js +41 -0
- package/src/engine/control/first-person/math/computeMassRatios.d.ts +35 -0
- package/src/engine/control/first-person/math/computeMassRatios.d.ts.map +1 -0
- package/src/engine/control/first-person/math/computeMassRatios.js +44 -0
- package/src/engine/control/first-person/pose/FirstPersonPose.d.ts +31 -1
- package/src/engine/control/first-person/pose/FirstPersonPose.d.ts.map +1 -1
- package/src/engine/control/first-person/pose/FirstPersonPose.js +49 -3
- package/src/engine/control/first-person/pose/FirstPersonPosture.d.ts +7 -0
- package/src/engine/control/first-person/pose/FirstPersonPosture.d.ts.map +1 -0
- package/src/engine/control/first-person/pose/FirstPersonPosture.js +27 -0
- package/src/engine/control/first-person/prototype_first_person_controller.js +550 -119
- package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts +58 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensors.d.ts.map +1 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensors.js +77 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts +80 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.d.ts.map +1 -0
- package/src/engine/control/first-person/sensors/FirstPersonSensorsSystem.js +196 -0
- package/src/engine/control/first-person/test/buildTestPlayer.d.ts +20 -0
- package/src/engine/control/first-person/test/buildTestPlayer.d.ts.map +1 -0
- package/src/engine/control/first-person/test/buildTestPlayer.js +28 -0
- package/src/engine/ecs/EntityManager.d.ts +2 -2
- package/src/engine/ecs/EntityManager.d.ts.map +1 -1
- package/src/engine/ecs/EntityManager.js +13 -8
- package/src/engine/ecs/System.d.ts.map +1 -1
- package/src/engine/ecs/System.js +2 -2
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -2
- package/src/engine/graphics/ecs/light/Light.d.ts.map +1 -1
- package/src/engine/graphics/ecs/light/Light.js +27 -0
- package/src/engine/graphics/ecs/light/LightSystem.js +1 -1
- package/src/engine/graphics/ecs/path/PathDisplaySystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
- package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +0 -2
- package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
- package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -2
- package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
- package/src/engine/navigation/grid/find_path_on_grid_astar.d.ts.map +1 -1
- package/src/engine/navigation/grid/find_path_on_grid_astar.js +11 -2
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.d.ts.map +1 -1
- package/src/engine/navigation/mesh/bt_mesh_face_find_path.js +11 -1
- package/src/engine/physics/PLAN.md +236 -0
- package/src/engine/physics/body/BodyStorage.d.ts +187 -0
- package/src/engine/physics/body/BodyStorage.d.ts.map +1 -0
- package/src/engine/physics/body/BodyStorage.js +427 -0
- package/src/engine/physics/broadphase/PairList.d.ts +62 -0
- package/src/engine/physics/broadphase/PairList.d.ts.map +1 -0
- package/src/engine/physics/broadphase/PairList.js +97 -0
- package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts +30 -0
- package/src/engine/physics/broadphase/aabb_transform_oriented.d.ts.map +1 -0
- package/src/engine/physics/broadphase/aabb_transform_oriented.js +93 -0
- package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts +16 -0
- package/src/engine/physics/broadphase/compute_fat_world_aabb.d.ts.map +1 -0
- package/src/engine/physics/broadphase/compute_fat_world_aabb.js +61 -0
- package/src/engine/physics/broadphase/generate_pairs.d.ts +38 -0
- package/src/engine/physics/broadphase/generate_pairs.d.ts.map +1 -0
- package/src/engine/physics/broadphase/generate_pairs.js +101 -0
- package/src/engine/physics/contact/ManifoldStore.d.ts +226 -0
- package/src/engine/physics/contact/ManifoldStore.d.ts.map +1 -0
- package/src/engine/physics/contact/ManifoldStore.js +499 -0
- package/src/engine/physics/ecs/BodyKind.d.ts +23 -0
- package/src/engine/physics/ecs/BodyKind.d.ts.map +1 -0
- package/src/engine/physics/ecs/BodyKind.js +24 -0
- package/src/engine/physics/ecs/Collider.d.ts +98 -0
- package/src/engine/physics/ecs/Collider.d.ts.map +1 -0
- package/src/engine/physics/ecs/Collider.js +136 -0
- package/src/engine/physics/ecs/ColliderFlags.d.ts +14 -0
- package/src/engine/physics/ecs/ColliderFlags.d.ts.map +1 -0
- package/src/engine/physics/ecs/ColliderFlags.js +15 -0
- package/src/engine/physics/ecs/ColliderObserverSystem.d.ts +58 -0
- package/src/engine/physics/ecs/ColliderObserverSystem.d.ts.map +1 -0
- package/src/engine/physics/ecs/ColliderObserverSystem.js +103 -0
- package/src/engine/physics/ecs/ColliderSerializationAdapter.d.ts +25 -0
- package/src/engine/physics/ecs/ColliderSerializationAdapter.d.ts.map +1 -0
- package/src/engine/physics/ecs/ColliderSerializationAdapter.js +37 -0
- package/src/engine/physics/ecs/PhysicsEvents.d.ts +15 -0
- package/src/engine/physics/ecs/PhysicsEvents.d.ts.map +1 -0
- package/src/engine/physics/ecs/PhysicsEvents.js +16 -0
- package/src/engine/physics/ecs/PhysicsSystem.d.ts +520 -0
- package/src/engine/physics/ecs/PhysicsSystem.d.ts.map +1 -0
- package/src/engine/physics/ecs/PhysicsSystem.js +1159 -0
- package/src/engine/physics/ecs/RigidBody.d.ts +197 -0
- package/src/engine/physics/ecs/RigidBody.d.ts.map +1 -0
- package/src/engine/physics/ecs/RigidBody.js +240 -0
- package/src/engine/physics/ecs/RigidBodyFlags.d.ts +21 -0
- package/src/engine/physics/ecs/RigidBodyFlags.d.ts.map +1 -0
- package/src/engine/physics/ecs/RigidBodyFlags.js +22 -0
- package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts +28 -0
- package/src/engine/physics/ecs/RigidBodySerializationAdapter.d.ts.map +1 -0
- package/src/engine/physics/ecs/RigidBodySerializationAdapter.js +81 -0
- package/src/engine/physics/ecs/SleepState.d.ts +11 -0
- package/src/engine/physics/ecs/SleepState.d.ts.map +1 -0
- package/src/engine/physics/ecs/SleepState.js +12 -0
- package/src/engine/physics/events/ContactEventBuffer.d.ts +46 -0
- package/src/engine/physics/events/ContactEventBuffer.d.ts.map +1 -0
- package/src/engine/physics/events/ContactEventBuffer.js +83 -0
- package/src/engine/physics/events/diff_manifolds.d.ts +25 -0
- package/src/engine/physics/events/diff_manifolds.d.ts.map +1 -0
- package/src/engine/physics/events/diff_manifolds.js +50 -0
- package/src/engine/physics/fluid/FluidField.d.ts +294 -16
- package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
- package/src/engine/physics/fluid/FluidField.js +510 -66
- package/src/engine/physics/fluid/FluidSimulator.d.ts +188 -5
- package/src/engine/physics/fluid/FluidSimulator.d.ts.map +1 -1
- package/src/engine/physics/fluid/FluidSimulator.js +455 -95
- package/src/engine/physics/fluid/SliceVisualiser.d.ts +29 -6
- package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
- package/src/engine/physics/fluid/SliceVisualiser.js +190 -165
- package/src/engine/physics/fluid/ecs/FluidComponent.d.ts +154 -0
- package/src/engine/physics/fluid/ecs/FluidComponent.d.ts.map +1 -0
- package/src/engine/physics/fluid/ecs/FluidComponent.js +238 -0
- package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.d.ts +45 -0
- package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.d.ts.map +1 -0
- package/src/engine/physics/fluid/ecs/FluidEffectorsComponent.js +89 -0
- package/src/engine/physics/fluid/ecs/FluidSystem.d.ts +107 -0
- package/src/engine/physics/fluid/ecs/FluidSystem.d.ts.map +1 -0
- package/src/engine/physics/fluid/ecs/FluidSystem.js +278 -0
- package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts +62 -1
- package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts.map +1 -1
- package/src/engine/physics/fluid/effector/AbstractFluidEffector.js +81 -6
- package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts +17 -4
- package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts.map +1 -1
- package/src/engine/physics/fluid/effector/GlobalFluidEffector.js +105 -12
- package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts +43 -0
- package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts.map +1 -0
- package/src/engine/physics/fluid/effector/ImpulseFluidEffector.js +210 -0
- package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts +62 -1
- package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts.map +1 -1
- package/src/engine/physics/fluid/effector/WakeFluidEffector.js +302 -8
- package/src/engine/physics/fluid/prototype.js +102 -91
- package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts +33 -0
- package/src/engine/physics/fluid/solver/optimal_sor_omega.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/optimal_sor_omega.js +41 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts +20 -5
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.d.ts.map +1 -1
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_forward.js +60 -38
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts +25 -4
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.d.ts.map +1 -1
- package/src/engine/physics/fluid/solver/v3_grid_apply_diffusion.js +93 -73
- package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts +23 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_apply_scalar_advection.js +60 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.d.ts +23 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_divergence.js +68 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts +30 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_compute_solid_neighbour_mask.js +66 -0
- package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.d.ts +26 -0
- package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_patch_edges_uniform.js +113 -0
- package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.d.ts +30 -0
- package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_shift_in_place.js +107 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts +49 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure.js +126 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts +93 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_pcg.js +424 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts +20 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_solve_pressure_unmasked_legacy.js +83 -0
- package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts +26 -0
- package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.d.ts.map +1 -0
- package/src/engine/physics/fluid/solver/v3_grid_subtract_pressure_gradient.js +70 -0
- package/src/engine/physics/gjk/expanding_polytope_algorithm.d.ts.map +1 -1
- package/src/engine/physics/gjk/expanding_polytope_algorithm.js +8 -10
- package/src/engine/physics/inertia/world_inverse_inertia.d.ts +29 -0
- package/src/engine/physics/inertia/world_inverse_inertia.d.ts.map +1 -0
- package/src/engine/physics/inertia/world_inverse_inertia.js +79 -0
- package/src/engine/physics/integration/integrate_position.d.ts +16 -0
- package/src/engine/physics/integration/integrate_position.d.ts.map +1 -0
- package/src/engine/physics/integration/integrate_position.js +48 -0
- package/src/engine/physics/integration/integrate_velocity.d.ts +25 -0
- package/src/engine/physics/integration/integrate_velocity.d.ts.map +1 -0
- package/src/engine/physics/integration/integrate_velocity.js +79 -0
- package/src/engine/physics/integration/quat_integrate.d.ts +27 -0
- package/src/engine/physics/integration/quat_integrate.d.ts.map +1 -0
- package/src/engine/physics/integration/quat_integrate.js +62 -0
- package/src/engine/physics/island/IslandBuilder.d.ts +167 -0
- package/src/engine/physics/island/IslandBuilder.d.ts.map +1 -0
- package/src/engine/physics/island/IslandBuilder.js +411 -0
- package/src/engine/physics/island/union_find.d.ts +51 -0
- package/src/engine/physics/island/union_find.d.ts.map +1 -0
- package/src/engine/physics/island/union_find.js +76 -0
- package/src/engine/physics/narrowphase/PosedShape.d.ts +59 -0
- package/src/engine/physics/narrowphase/PosedShape.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/PosedShape.js +110 -0
- package/src/engine/physics/narrowphase/box_box_manifold.d.ts +32 -0
- package/src/engine/physics/narrowphase/box_box_manifold.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/box_box_manifold.js +543 -0
- package/src/engine/physics/narrowphase/capsule_contacts.d.ts +122 -0
- package/src/engine/physics/narrowphase/capsule_contacts.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/capsule_contacts.js +508 -0
- package/src/engine/physics/narrowphase/narrowphase_step.d.ts +11 -0
- package/src/engine/physics/narrowphase/narrowphase_step.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/narrowphase_step.js +382 -0
- package/src/engine/physics/narrowphase/sphere_box_contact.d.ts +38 -0
- package/src/engine/physics/narrowphase/sphere_box_contact.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/sphere_box_contact.js +130 -0
- package/src/engine/physics/narrowphase/sphere_sphere_contact.d.ts +26 -0
- package/src/engine/physics/narrowphase/sphere_sphere_contact.d.ts.map +1 -0
- package/src/engine/physics/narrowphase/sphere_sphere_contact.js +51 -0
- package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts +83 -0
- package/src/engine/physics/queries/PhysicsSurfacePoint.d.ts.map +1 -0
- package/src/engine/physics/queries/PhysicsSurfacePoint.js +100 -0
- package/src/engine/physics/queries/raycast.d.ts +20 -0
- package/src/engine/physics/queries/raycast.d.ts.map +1 -0
- package/src/engine/physics/queries/raycast.js +249 -0
- package/src/engine/physics/solver/friction_cone.d.ts +16 -0
- package/src/engine/physics/solver/friction_cone.d.ts.map +1 -0
- package/src/engine/physics/solver/friction_cone.js +37 -0
- package/src/engine/physics/solver/solve_contacts.d.ts +36 -0
- package/src/engine/physics/solver/solve_contacts.d.ts.map +1 -0
- package/src/engine/physics/solver/solve_contacts.js +598 -0
- package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.d.ts +0 -34
- package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.d.ts.map +0 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/OrderedEdge.js +0 -66
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.d.ts +0 -2
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.d.ts.map +0 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_calc_edges.js +0 -54
- package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.d.ts +0 -2
- package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.d.ts.map +0 -1
- package/src/core/geom/3d/topology/struct/binary/io/edge/get_or_create_edge_map.js +0 -26
- package/src/engine/ecs/components/Motion.d.ts +0 -21
- package/src/engine/ecs/components/Motion.d.ts.map +0 -1
- package/src/engine/ecs/components/Motion.js +0 -27
- package/src/engine/ecs/components/MotionSerializationAdapter.d.ts +0 -20
- package/src/engine/ecs/components/MotionSerializationAdapter.d.ts.map +0 -1
- package/src/engine/ecs/components/MotionSerializationAdapter.js +0 -26
- package/src/engine/ecs/systems/MotionSystem.d.ts +0 -9
- package/src/engine/ecs/systems/MotionSystem.d.ts.map +0 -1
- package/src/engine/ecs/systems/MotionSystem.js +0 -29
- package/src/engine/physics/fluid/Fluid.d.ts +0 -26
- package/src/engine/physics/fluid/Fluid.d.ts.map +0 -1
- package/src/engine/physics/fluid/Fluid.js +0 -221
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.d.ts +0 -7
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.d.ts.map +0 -1
- package/src/engine/physics/fluid/solver/v3_grid_apply_advection_reverse.js +0 -8
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
import { BinaryElementPool } from "../../geom/3d/topology/struct/binary/BinaryElementPool.js";
|
|
3
|
+
|
|
4
|
+
const UINT32_MAX = 4294967295;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sentinel for "no such node" — matches Boost's `(size_type)(-1)` convention.
|
|
8
|
+
* Valid node handles are 0 .. UINT32_MAX - 1.
|
|
9
|
+
* @type {number}
|
|
10
|
+
*/
|
|
11
|
+
const NULL_HANDLE = UINT32_MAX;
|
|
12
|
+
|
|
13
|
+
/*
|
|
14
|
+
* Node record layout — 32 bytes / 8 words per node, kept word-aligned so that one record fits inside half
|
|
15
|
+
* a typical 64 B cache line. All fields are uint32 except `key`, which is float32; both views are aliased
|
|
16
|
+
* onto the same backing ArrayBuffer via {@link BinaryElementPool}.
|
|
17
|
+
*
|
|
18
|
+
* word 0 : key (float32) — priority / score
|
|
19
|
+
* word 1 : id (uint32) — client-supplied identifier
|
|
20
|
+
* word 2 : parent (uint32) — handle, NULL_HANDLE if at root
|
|
21
|
+
* word 3 : child (uint32) — handle of an arbitrary child, NULL_HANDLE if leaf
|
|
22
|
+
* word 4 : left (uint32) — left sibling in the circular doubly-linked list
|
|
23
|
+
* word 5 : right (uint32) — right sibling in the circular doubly-linked list
|
|
24
|
+
* word 6 : degree (uint32) — number of children
|
|
25
|
+
* word 7 : mark (uint32) — 0 or 1, set by cascading cuts
|
|
26
|
+
*/
|
|
27
|
+
const RECORD_WORD_SIZE = 8;
|
|
28
|
+
const RECORD_BYTE_SIZE = RECORD_WORD_SIZE * 4;
|
|
29
|
+
|
|
30
|
+
const FIELD_KEY = 0;
|
|
31
|
+
const FIELD_ID = 1;
|
|
32
|
+
const FIELD_PARENT = 2;
|
|
33
|
+
const FIELD_CHILD = 3;
|
|
34
|
+
const FIELD_LEFT = 4;
|
|
35
|
+
const FIELD_RIGHT = 5;
|
|
36
|
+
const FIELD_DEGREE = 6;
|
|
37
|
+
const FIELD_MARK = 7;
|
|
38
|
+
|
|
39
|
+
const DEFAULT_CAPACITY = 64;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Fibonacci heap implementation that stores uint32 ID along with a floating point score value, intended to be
|
|
43
|
+
* API-compatible with {@link Uint32Heap}.
|
|
44
|
+
*
|
|
45
|
+
* Storage is struct-of-arrays on top of a single {@link BinaryElementPool} — each "node" is a 32-byte
|
|
46
|
+
* record in a contiguous ArrayBuffer, and "node references" are uint32 handles rather than object pointers.
|
|
47
|
+
* This keeps all per-node state in continuous memory, avoiding the per-element allocation and pointer chasing
|
|
48
|
+
* of an object-graph implementation.
|
|
49
|
+
*
|
|
50
|
+
* Fibonacci heaps have theoretically excellent asymptotic bounds:
|
|
51
|
+
* - insert, find-min, decrease-key: amortized O(1)
|
|
52
|
+
* - extract-min, delete: amortized O(log n)
|
|
53
|
+
*
|
|
54
|
+
* In practice they often lose to a simple binary or 4-ary heap on graph-search workloads because of poor
|
|
55
|
+
* cache behavior; this layout closes most of that gap by removing the indirection. See Larkin, Sen & Tarjan
|
|
56
|
+
* (2014), "A Back-to-Basics Empirical Study of Priority Queues" (arXiv:1403.0252) for the empirical context.
|
|
57
|
+
*
|
|
58
|
+
* Reference: Cormen, Leiserson, Rivest, Stein, "Introduction to Algorithms", 3rd ed., chapter 19.
|
|
59
|
+
*
|
|
60
|
+
* @see Uint32Heap
|
|
61
|
+
* @see Uint32Heap4
|
|
62
|
+
*/
|
|
63
|
+
export class FibonacciHeap {
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
*
|
|
67
|
+
* @param {number} [initial_capacity] reserves space for this many nodes up front. The pool grows on demand.
|
|
68
|
+
*/
|
|
69
|
+
constructor(initial_capacity = DEFAULT_CAPACITY) {
|
|
70
|
+
assert.isNonNegativeInteger(initial_capacity, 'initial_capacity');
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @type {BinaryElementPool}
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
this.__pool = new BinaryElementPool(RECORD_BYTE_SIZE, initial_capacity);
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Handle of the node with the smallest key, or NULL_HANDLE if empty.
|
|
80
|
+
* @type {number}
|
|
81
|
+
* @private
|
|
82
|
+
*/
|
|
83
|
+
this.__min = NULL_HANDLE;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Number of nodes currently in the heap.
|
|
87
|
+
* @type {number}
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
this.__size = 0;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Id -> handle lookup, allows update_score / remove / contains / get_score in O(1) expected.
|
|
94
|
+
*
|
|
95
|
+
* Empirically (see the bench tests in FibonacciHeap.spec.js), V8's built-in Map beats a hand-rolled
|
|
96
|
+
* Uint32Array-backed Robin Hood hash table for this workload by 20-90 % on hot paths. Reason: every
|
|
97
|
+
* key and value here is SMI (ids and handles are both small), so V8 Map's native C++ SMI fast path
|
|
98
|
+
* never boxes; meanwhile a JS-side flat-array implementation pays per-probe Math.imul + bounds-checks
|
|
99
|
+
* that V8's compiled Map sidesteps. The Uint32Map primitive lives at core/collection/Uint32Map.js
|
|
100
|
+
* and is the right choice when keys/values exceed 2^30 (V8 Map boxes) or when delete churn is
|
|
101
|
+
* extreme (V8 Map tombstone-rots until rehash) — but not here.
|
|
102
|
+
*
|
|
103
|
+
* @type {Map<number, number>}
|
|
104
|
+
* @private
|
|
105
|
+
*/
|
|
106
|
+
this.__handles = new Map();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @returns {number}
|
|
112
|
+
*/
|
|
113
|
+
get size() {
|
|
114
|
+
return this.__size;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Node with the lowest score
|
|
119
|
+
* @returns {number}
|
|
120
|
+
*/
|
|
121
|
+
get top_id() {
|
|
122
|
+
if (this.__min === NULL_HANDLE) {
|
|
123
|
+
return 0;
|
|
124
|
+
}
|
|
125
|
+
return this.__pool.data_uint32[(this.__min * RECORD_WORD_SIZE) + FIELD_ID];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
* @returns {boolean}
|
|
131
|
+
*/
|
|
132
|
+
is_empty() {
|
|
133
|
+
return this.__size === 0;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Returns the score of the node with the lowest score
|
|
138
|
+
* @returns {number}
|
|
139
|
+
*/
|
|
140
|
+
peek_score() {
|
|
141
|
+
if (this.__min === NULL_HANDLE) {
|
|
142
|
+
return Number.NaN;
|
|
143
|
+
}
|
|
144
|
+
return this.__pool.data_float32[(this.__min * RECORD_WORD_SIZE) + FIELD_KEY];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Returns the ID of the node with the lowest score
|
|
149
|
+
* @returns {number}
|
|
150
|
+
*/
|
|
151
|
+
peek_min() {
|
|
152
|
+
return this.top_id;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Splice `handle` (a single-element circular list) into the root list to the right of `__min`. The caller
|
|
157
|
+
* is responsible for setting parent and degree on `handle`.
|
|
158
|
+
*
|
|
159
|
+
* @private
|
|
160
|
+
* @param {number} handle
|
|
161
|
+
*/
|
|
162
|
+
__root_insert(handle) {
|
|
163
|
+
const u32 = this.__pool.data_uint32;
|
|
164
|
+
const f32 = this.__pool.data_float32;
|
|
165
|
+
const min = this.__min;
|
|
166
|
+
const handle_base = handle * RECORD_WORD_SIZE;
|
|
167
|
+
|
|
168
|
+
if (min === NULL_HANDLE) {
|
|
169
|
+
// first node — it is its own root list
|
|
170
|
+
u32[handle_base + FIELD_LEFT] = handle;
|
|
171
|
+
u32[handle_base + FIELD_RIGHT] = handle;
|
|
172
|
+
this.__min = handle;
|
|
173
|
+
} else {
|
|
174
|
+
// splice in to the right of min
|
|
175
|
+
const min_base = min * RECORD_WORD_SIZE;
|
|
176
|
+
const min_right = u32[min_base + FIELD_RIGHT];
|
|
177
|
+
|
|
178
|
+
u32[handle_base + FIELD_LEFT] = min;
|
|
179
|
+
u32[handle_base + FIELD_RIGHT] = min_right;
|
|
180
|
+
u32[(min_right * RECORD_WORD_SIZE) + FIELD_LEFT] = handle;
|
|
181
|
+
u32[min_base + FIELD_RIGHT] = handle;
|
|
182
|
+
|
|
183
|
+
if (f32[handle_base + FIELD_KEY] < f32[min_base + FIELD_KEY]) {
|
|
184
|
+
this.__min = handle;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Remove `handle` from its sibling list (root list or child list of some parent). Sibling pointers of
|
|
191
|
+
* `handle` are left dangling; the caller is expected to re-link it immediately.
|
|
192
|
+
*
|
|
193
|
+
* @private
|
|
194
|
+
* @param {number} handle
|
|
195
|
+
*/
|
|
196
|
+
__unlink_from_siblings(handle) {
|
|
197
|
+
const u32 = this.__pool.data_uint32;
|
|
198
|
+
const base = handle * RECORD_WORD_SIZE;
|
|
199
|
+
|
|
200
|
+
const left = u32[base + FIELD_LEFT];
|
|
201
|
+
const right = u32[base + FIELD_RIGHT];
|
|
202
|
+
|
|
203
|
+
u32[(left * RECORD_WORD_SIZE) + FIELD_RIGHT] = right;
|
|
204
|
+
u32[(right * RECORD_WORD_SIZE) + FIELD_LEFT] = left;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
*
|
|
209
|
+
* @param {number} id
|
|
210
|
+
* @param {number} score
|
|
211
|
+
*/
|
|
212
|
+
insert(id, score) {
|
|
213
|
+
assert.isNonNegativeInteger(id, 'id');
|
|
214
|
+
assert.lessThanOrEqual(id, UINT32_MAX - 1, 'id must be <= (2^32 - 2)');
|
|
215
|
+
assert.isNumber(score, 'score');
|
|
216
|
+
assert.notNaN(score, 'score');
|
|
217
|
+
|
|
218
|
+
// pool.allocate() may grow the underlying buffer, so re-fetch views *after* the call
|
|
219
|
+
const handle = this.__pool.allocate();
|
|
220
|
+
const u32 = this.__pool.data_uint32;
|
|
221
|
+
const f32 = this.__pool.data_float32;
|
|
222
|
+
const base = handle * RECORD_WORD_SIZE;
|
|
223
|
+
|
|
224
|
+
// a recycled slot retains stale bytes from its previous occupant — initialize every field explicitly
|
|
225
|
+
f32[base + FIELD_KEY] = score;
|
|
226
|
+
u32[base + FIELD_ID] = id;
|
|
227
|
+
u32[base + FIELD_PARENT] = NULL_HANDLE;
|
|
228
|
+
u32[base + FIELD_CHILD] = NULL_HANDLE;
|
|
229
|
+
u32[base + FIELD_LEFT] = handle;
|
|
230
|
+
u32[base + FIELD_RIGHT] = handle;
|
|
231
|
+
u32[base + FIELD_DEGREE] = 0;
|
|
232
|
+
u32[base + FIELD_MARK] = 0;
|
|
233
|
+
|
|
234
|
+
this.__root_insert(handle);
|
|
235
|
+
|
|
236
|
+
this.__handles.set(id, handle);
|
|
237
|
+
this.__size++;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Removed and returns the ID of the node with the lowest score.
|
|
242
|
+
*
|
|
243
|
+
* @returns {number}
|
|
244
|
+
*/
|
|
245
|
+
pop_min() {
|
|
246
|
+
const z = this.__min;
|
|
247
|
+
|
|
248
|
+
assert.notEqual(z, NULL_HANDLE, 'heap is empty');
|
|
249
|
+
|
|
250
|
+
const u32 = this.__pool.data_uint32;
|
|
251
|
+
const z_base = z * RECORD_WORD_SIZE;
|
|
252
|
+
const z_id = u32[z_base + FIELD_ID];
|
|
253
|
+
|
|
254
|
+
// promote all of z's children to the root list
|
|
255
|
+
const child = u32[z_base + FIELD_CHILD];
|
|
256
|
+
if (child !== NULL_HANDLE) {
|
|
257
|
+
// walk the child list, clearing parent pointers
|
|
258
|
+
let c = child;
|
|
259
|
+
do {
|
|
260
|
+
u32[(c * RECORD_WORD_SIZE) + FIELD_PARENT] = NULL_HANDLE;
|
|
261
|
+
c = u32[(c * RECORD_WORD_SIZE) + FIELD_RIGHT];
|
|
262
|
+
} while (c !== child);
|
|
263
|
+
|
|
264
|
+
// splice the child list into the root list, immediately to the right of z.
|
|
265
|
+
// both are circular doubly-linked lists; standard list-concat trick:
|
|
266
|
+
const z_right = u32[z_base + FIELD_RIGHT];
|
|
267
|
+
const child_base = child * RECORD_WORD_SIZE;
|
|
268
|
+
const child_left = u32[child_base + FIELD_LEFT];
|
|
269
|
+
|
|
270
|
+
u32[z_base + FIELD_RIGHT] = child;
|
|
271
|
+
u32[child_base + FIELD_LEFT] = z;
|
|
272
|
+
|
|
273
|
+
u32[(child_left * RECORD_WORD_SIZE) + FIELD_RIGHT] = z_right;
|
|
274
|
+
u32[(z_right * RECORD_WORD_SIZE) + FIELD_LEFT] = child_left;
|
|
275
|
+
|
|
276
|
+
u32[z_base + FIELD_CHILD] = NULL_HANDLE;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// snapshot before the unlink rewrites z's sibling pointers
|
|
280
|
+
const z_right_after_merge = u32[z_base + FIELD_RIGHT];
|
|
281
|
+
|
|
282
|
+
// remove z from the root list
|
|
283
|
+
this.__unlink_from_siblings(z);
|
|
284
|
+
|
|
285
|
+
if (z === z_right_after_merge) {
|
|
286
|
+
// z was the only node remaining
|
|
287
|
+
this.__min = NULL_HANDLE;
|
|
288
|
+
} else {
|
|
289
|
+
// tentatively set min to z's old right neighbor; consolidation will pick the real min
|
|
290
|
+
this.__min = z_right_after_merge;
|
|
291
|
+
this.__consolidate();
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
this.__size--;
|
|
295
|
+
this.__handles.delete(z_id);
|
|
296
|
+
this.__pool.release(z);
|
|
297
|
+
|
|
298
|
+
return z_id;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Merge trees of equal degree until every degree is unique among the roots. Sets `__min` to the true
|
|
303
|
+
* minimum.
|
|
304
|
+
*
|
|
305
|
+
* @private
|
|
306
|
+
*/
|
|
307
|
+
__consolidate() {
|
|
308
|
+
const u32 = this.__pool.data_uint32;
|
|
309
|
+
const f32 = this.__pool.data_float32;
|
|
310
|
+
|
|
311
|
+
// upper bound on max degree D(n) <= floor(log_phi(n)).
|
|
312
|
+
// log_phi(n) = log2(n) / log2(phi) ~= log2(n) * 1.4404; pad generously.
|
|
313
|
+
const D = Math.floor(Math.log2(this.__size)) * 2 + 8;
|
|
314
|
+
const A = new Array(D);
|
|
315
|
+
for (let i = 0; i < D; i++) {
|
|
316
|
+
A[i] = NULL_HANDLE;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// snapshot the current root list — the list is mutated during link, so iterate over a stable copy
|
|
320
|
+
const roots = [];
|
|
321
|
+
const start = this.__min;
|
|
322
|
+
let w = start;
|
|
323
|
+
do {
|
|
324
|
+
roots.push(w);
|
|
325
|
+
w = u32[(w * RECORD_WORD_SIZE) + FIELD_RIGHT];
|
|
326
|
+
} while (w !== start);
|
|
327
|
+
|
|
328
|
+
for (let i = 0; i < roots.length; i++) {
|
|
329
|
+
let x = roots[i];
|
|
330
|
+
let d = u32[(x * RECORD_WORD_SIZE) + FIELD_DEGREE];
|
|
331
|
+
|
|
332
|
+
while (A[d] !== NULL_HANDLE) {
|
|
333
|
+
let y = A[d];
|
|
334
|
+
|
|
335
|
+
if (f32[(x * RECORD_WORD_SIZE) + FIELD_KEY] > f32[(y * RECORD_WORD_SIZE) + FIELD_KEY]) {
|
|
336
|
+
// swap so x is the smaller-key root
|
|
337
|
+
const tmp = x;
|
|
338
|
+
x = y;
|
|
339
|
+
y = tmp;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
this.__link(y, x);
|
|
343
|
+
|
|
344
|
+
A[d] = NULL_HANDLE;
|
|
345
|
+
d++;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
A[d] = x;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// rebuild the root list from A[] and find the new min
|
|
352
|
+
this.__min = NULL_HANDLE;
|
|
353
|
+
for (let i = 0; i < D; i++) {
|
|
354
|
+
const a = A[i];
|
|
355
|
+
if (a !== NULL_HANDLE) {
|
|
356
|
+
// detach (it may still point to old neighbors that no longer reference it)
|
|
357
|
+
const a_base = a * RECORD_WORD_SIZE;
|
|
358
|
+
u32[a_base + FIELD_LEFT] = a;
|
|
359
|
+
u32[a_base + FIELD_RIGHT] = a;
|
|
360
|
+
this.__root_insert(a);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Make `y` (currently in the root list) a child of `x`.
|
|
367
|
+
*
|
|
368
|
+
* @private
|
|
369
|
+
* @param {number} y
|
|
370
|
+
* @param {number} x
|
|
371
|
+
*/
|
|
372
|
+
__link(y, x) {
|
|
373
|
+
const u32 = this.__pool.data_uint32;
|
|
374
|
+
|
|
375
|
+
// remove y from the root list
|
|
376
|
+
this.__unlink_from_siblings(y);
|
|
377
|
+
|
|
378
|
+
const x_base = x * RECORD_WORD_SIZE;
|
|
379
|
+
const y_base = y * RECORD_WORD_SIZE;
|
|
380
|
+
|
|
381
|
+
const x_child = u32[x_base + FIELD_CHILD];
|
|
382
|
+
if (x_child === NULL_HANDLE) {
|
|
383
|
+
u32[x_base + FIELD_CHILD] = y;
|
|
384
|
+
u32[y_base + FIELD_LEFT] = y;
|
|
385
|
+
u32[y_base + FIELD_RIGHT] = y;
|
|
386
|
+
} else {
|
|
387
|
+
// splice y into x's child list
|
|
388
|
+
const x_child_base = x_child * RECORD_WORD_SIZE;
|
|
389
|
+
const x_child_right = u32[x_child_base + FIELD_RIGHT];
|
|
390
|
+
|
|
391
|
+
u32[y_base + FIELD_LEFT] = x_child;
|
|
392
|
+
u32[y_base + FIELD_RIGHT] = x_child_right;
|
|
393
|
+
u32[(x_child_right * RECORD_WORD_SIZE) + FIELD_LEFT] = y;
|
|
394
|
+
u32[x_child_base + FIELD_RIGHT] = y;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
u32[y_base + FIELD_PARENT] = x;
|
|
398
|
+
u32[x_base + FIELD_DEGREE]++;
|
|
399
|
+
u32[y_base + FIELD_MARK] = 0;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Decrease the key of `handle` to `new_key`. `new_key` must be <= current key.
|
|
404
|
+
*
|
|
405
|
+
* @private
|
|
406
|
+
* @param {number} handle
|
|
407
|
+
* @param {number} new_key
|
|
408
|
+
*/
|
|
409
|
+
__decrease_key(handle, new_key) {
|
|
410
|
+
const u32 = this.__pool.data_uint32;
|
|
411
|
+
const f32 = this.__pool.data_float32;
|
|
412
|
+
const base = handle * RECORD_WORD_SIZE;
|
|
413
|
+
|
|
414
|
+
assert.lessThanOrEqual(new_key, f32[base + FIELD_KEY], 'new key is greater than current key');
|
|
415
|
+
|
|
416
|
+
f32[base + FIELD_KEY] = new_key;
|
|
417
|
+
|
|
418
|
+
const parent = u32[base + FIELD_PARENT];
|
|
419
|
+
if (parent !== NULL_HANDLE && new_key < f32[(parent * RECORD_WORD_SIZE) + FIELD_KEY]) {
|
|
420
|
+
this.__cut(handle, parent);
|
|
421
|
+
this.__cascading_cut(parent);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (new_key < f32[(this.__min * RECORD_WORD_SIZE) + FIELD_KEY]) {
|
|
425
|
+
this.__min = handle;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Cut `x` from `y`'s child list and promote it to the root list.
|
|
431
|
+
*
|
|
432
|
+
* @private
|
|
433
|
+
* @param {number} x child being cut
|
|
434
|
+
* @param {number} y parent of x
|
|
435
|
+
*/
|
|
436
|
+
__cut(x, y) {
|
|
437
|
+
const u32 = this.__pool.data_uint32;
|
|
438
|
+
const x_base = x * RECORD_WORD_SIZE;
|
|
439
|
+
const y_base = y * RECORD_WORD_SIZE;
|
|
440
|
+
|
|
441
|
+
const x_right = u32[x_base + FIELD_RIGHT];
|
|
442
|
+
|
|
443
|
+
if (x_right === x) {
|
|
444
|
+
// x was the only child of y
|
|
445
|
+
u32[y_base + FIELD_CHILD] = NULL_HANDLE;
|
|
446
|
+
} else {
|
|
447
|
+
if (u32[y_base + FIELD_CHILD] === x) {
|
|
448
|
+
// y was pointing at x — point at a sibling instead
|
|
449
|
+
u32[y_base + FIELD_CHILD] = x_right;
|
|
450
|
+
}
|
|
451
|
+
this.__unlink_from_siblings(x);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
u32[y_base + FIELD_DEGREE]--;
|
|
455
|
+
|
|
456
|
+
// single-element circular list, then insert at root
|
|
457
|
+
u32[x_base + FIELD_LEFT] = x;
|
|
458
|
+
u32[x_base + FIELD_RIGHT] = x;
|
|
459
|
+
u32[x_base + FIELD_PARENT] = NULL_HANDLE;
|
|
460
|
+
u32[x_base + FIELD_MARK] = 0;
|
|
461
|
+
|
|
462
|
+
this.__root_insert(x);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Walk up from `y`, cutting marked ancestors and marking unmarked ones.
|
|
467
|
+
*
|
|
468
|
+
* @private
|
|
469
|
+
* @param {number} y
|
|
470
|
+
*/
|
|
471
|
+
__cascading_cut(y) {
|
|
472
|
+
const u32 = this.__pool.data_uint32;
|
|
473
|
+
const y_base = y * RECORD_WORD_SIZE;
|
|
474
|
+
|
|
475
|
+
const z = u32[y_base + FIELD_PARENT];
|
|
476
|
+
if (z !== NULL_HANDLE) {
|
|
477
|
+
if (u32[y_base + FIELD_MARK] === 0) {
|
|
478
|
+
u32[y_base + FIELD_MARK] = 1;
|
|
479
|
+
} else {
|
|
480
|
+
this.__cut(y, z);
|
|
481
|
+
this.__cascading_cut(z);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Delete the node referenced by `handle` by decreasing its key to -Infinity and popping the min.
|
|
488
|
+
*
|
|
489
|
+
* @private
|
|
490
|
+
* @param {number} handle
|
|
491
|
+
*/
|
|
492
|
+
__delete_handle(handle) {
|
|
493
|
+
this.__decrease_key(handle, Number.NEGATIVE_INFINITY);
|
|
494
|
+
this.pop_min();
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
*
|
|
499
|
+
* @param {number} id
|
|
500
|
+
* @returns {boolean}
|
|
501
|
+
*/
|
|
502
|
+
contains(id) {
|
|
503
|
+
return this.__handles.has(id);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
*
|
|
508
|
+
* @param {number} id
|
|
509
|
+
* @returns {number} score of the element with the given id, NaN if not found
|
|
510
|
+
*/
|
|
511
|
+
get_score(id) {
|
|
512
|
+
const handle = this.__handles.get(id);
|
|
513
|
+
if (handle === undefined) {
|
|
514
|
+
return Number.NaN;
|
|
515
|
+
}
|
|
516
|
+
return this.__pool.data_float32[(handle * RECORD_WORD_SIZE) + FIELD_KEY];
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
*
|
|
521
|
+
* @param {number} id
|
|
522
|
+
* @param {number} score
|
|
523
|
+
*/
|
|
524
|
+
update_score(id, score) {
|
|
525
|
+
const handle = this.__handles.get(id);
|
|
526
|
+
|
|
527
|
+
if (handle === undefined) {
|
|
528
|
+
throw new Error('Not found');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
assert.isNumber(score, 'score');
|
|
532
|
+
assert.notNaN(score, 'score');
|
|
533
|
+
|
|
534
|
+
const current = this.__pool.data_float32[(handle * RECORD_WORD_SIZE) + FIELD_KEY];
|
|
535
|
+
|
|
536
|
+
if (score < current) {
|
|
537
|
+
this.__decrease_key(handle, score);
|
|
538
|
+
} else if (score > current) {
|
|
539
|
+
// increase-key: delete and re-insert
|
|
540
|
+
this.__delete_handle(handle);
|
|
541
|
+
this.insert(id, score);
|
|
542
|
+
}
|
|
543
|
+
// score === current: no-op
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* Insert or update an element, if the element already exists, its score will be updated.
|
|
548
|
+
*
|
|
549
|
+
* @param {number} id
|
|
550
|
+
* @param {number} score
|
|
551
|
+
*/
|
|
552
|
+
insert_or_update(id, score) {
|
|
553
|
+
if (this.__handles.has(id)) {
|
|
554
|
+
this.update_score(id, score);
|
|
555
|
+
} else {
|
|
556
|
+
this.insert(id, score);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
*
|
|
562
|
+
* @param {number} id
|
|
563
|
+
* @returns {boolean}
|
|
564
|
+
*/
|
|
565
|
+
remove(id) {
|
|
566
|
+
const handle = this.__handles.get(id);
|
|
567
|
+
|
|
568
|
+
if (handle === undefined) {
|
|
569
|
+
return false;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
this.__delete_handle(handle);
|
|
573
|
+
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Clear out all the data, heap will be made empty
|
|
579
|
+
*/
|
|
580
|
+
clear() {
|
|
581
|
+
this.__min = NULL_HANDLE;
|
|
582
|
+
this.__size = 0;
|
|
583
|
+
this.__handles.clear();
|
|
584
|
+
this.__pool.clear();
|
|
585
|
+
}
|
|
586
|
+
}
|