void k_closest_points(KInt2 Xq, int cnt, List <int> idxs) { // initialize search data Bmin = KInt2.min; Bmax = KInt2.max; this.k = cnt; // call search on the root [0] fill the queue // with elements from the search knn_search(Xq); // scan the created pq and extract the first "k" elements // pop the remaining int N = pq.size(); for (int i = 0; i < N; i++) { ClsTuple <float, int> topel = pq.top(); pq.pop(); if (i >= N - k) { idxs.Add(topel.Value); } } // invert the vector, passing first closest results idxs.Reverse(); }
// this does not work, how do you provide a new ordering function to is_heap?? /// check recursively if the substructures is correct using STL provided algorithm //bool verifyHeap( ){ // return std::__is_heap(heap.begin(), heap.end() ); //} /// computes full heap sort and returns the corresponding indexing structure /// Requires the indexes to be allocated already. public void heapsort(List <int> indexes) { // until empty... keep popping int i = 0; while (empty() == false) { ClsTuple <Tkey, int> t = top(); pop(); indexes[i++] = t.Value; } }
protected override void Awake () { base.Awake (); using(var cc = new ClsTuple<int,float>()) { cc.field0 =12; cc.field1 = 123f; } BaseView.Create<BaseView>(this,new HideTrans(gameObject)); }
/// swap the content of two elements in position pos1 and pos2 private void swap(int pos1, int pos2) { Debug.Assert(heap.Count != 0); Debug.Assert(pos1 >= 0 && pos1 < heap.Count); Debug.Assert(pos2 >= 0 && pos2 < heap.Count); // update backindexes if (useBackIdx) { backIdx[heap[pos1].Value] = pos2; backIdx[heap[pos2].Value] = pos1; } // update heap ClsTuple <Tkey, int> temp = heap[pos1]; heap[pos1] = heap[pos2]; heap[pos2] = temp; }