Repository navigation
Conversation
KDTree sorted a copy of the cells at every level and split it into sublists. It now selects only the median inside one array (Wirth's quickselect) and recurses on index ranges. Hex cell centres share x per column, so the partition closes in from both ends; a one-sided partition is O(n^2) on equal keys. The caller's list is not reordered. HexCellRegistry.setPoint no longer replaces a cell that is already registered, so the cell it returns is the one the tree holds. Only marking the tree dirty when the set of cells changes was already in place here. Same change as MapConductor/js-sdk-core#20.
Contributor
Author
|
K-D 木は 928e7c3 で MarkerGridIndex に置き換え済みで、HexCellRegistry/KDTree はマーカー検索で使われていないため、この最適化は不要。K-D 木そのものの削除は別 PR で行う。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MapConductor/js-sdk-core#20 と同じ修正の Android 版。
js-sdk-core#20 との対応
pointerdownでドラッグ可能なマーカーが無ければ引き当てないHexCellRegistry:セルの集合が変わったときだけ作り直しの印を付けるHexCellRegistry:既にあるセルは置き換えないKDTree:quickselect で構築修正
KDTree:階層ごとにセルを並べ替えてsubListで分けていたのをやめ、1 本の配列の中で中央値だけを選んで(Wirth の quickselect)、添字の範囲で再帰する。六角セルの中心は列ごとに同じ x を持ち、等しい値が大量に並ぶので、左右から寄せる分割にした。渡されたリストは並べ替えないHexCellRegistry.setPoint:既にあるセルはputIfAbsentで置き換えず、返すのもそのセルにする(木が持っているセルと揃える)。同じセルのままの更新でも、登録済みのセルを返す公開 API の変更は無い。
確認
./gradlew testDebugUnitTest:295 件すべて通るKDTreeBuildTestnearest/withinRadiusWithDistance/nearestKWithDistanceが総当たりと一致する(同じ座標が並ぶ 40×40 の格子・ばらばらの 3,000 点)HexCellRegistryRebuildTest(5 件)・KDTreeRadiusTestも通る