public void DisConnectNode(PathNode _a, PathNode _b) { int index = -1; index = CQuickSort.Search <PathNode>(_a.mLink, _b, SortPathNodeCompare); if (index >= 0) { _a.mLink.RemoveAt(index); } index = CQuickSort.Search <PathNode>(_b.mLink, _a, SortPathNodeCompare); if (index >= 0) { _b.mLink.RemoveAt(index); } index = CQuickSort.Search <int>(_a.mLinkID, _b.mId, SortIntCompare); if (index >= 0) { _a.mLinkID.RemoveAt(index); } index = CQuickSort.Search <int>(_b.mLinkID, _a.mId, SortIntCompare); if (index >= 0) { _b.mLinkID.RemoveAt(index); } }
public T this[K _key] { get { T obj; if (TryGet(_key, out obj)) { return(obj); } return(default(T)); } set { int index = CQuickSort.Search <K>(mListKey, _key, CompareFunction); if (index < 0) { Add(_key, value); throw new Exception("Key not exist, key " + _key); } else { mListValue[index] = value; } } }
// static void swap(List<T> arr, int index1, int index2) // { // T tmp = arr[index1]; // arr[index1] = arr[index2]; // arr[index2] = tmp; // } // static T SelectMedian(List<T> a, int left, int right, CompareFunction<T> _compareFunction, params object[] args) // { // int midIndex = (left + right)>>1; // int diff = _compareFunction(a[left], a[midIndex], args); // if (diff > 0) // { // swap(a, left, midIndex); // } // diff = _compareFunction(a[left], a[right], args); // if (diff > 0) // { // swap(a, left, right); // } // diff = _compareFunction(a[midIndex], a[right], args); // if (diff > 0) // { // swap(a, midIndex, right); // } // swap(a, midIndex, right); // return a[right-1]; //返回中轴 // } ////// test ////////////////////////// public static void test_find() { List <int> arr = new List <int>(10); arr.Add(2); arr.Add(9); arr.Add(4); arr.Add(5); arr.Add(3); arr.Add(2); arr.Add(8); arr.Add(1); arr.Add(7); CQuickSort.Sort <int>(arr, 0, arr.Count - 1, test_compare_function); string out1 = ""; for (int i = 0; i < arr.Count; i++) { out1 += " " + arr[i].ToString(); } //Debug.LogError(out1); int _index = -1; _index = CQuickSort.Search <int>(arr, 9, test_compare_function); //Debug.LogError("_index " + _index); }
public void RemoveNode(PathNode _a) { int index = CQuickSort.Search <PathNode>(mListNodes, _a, SortPathNodeCompare); if (index >= 0) { mListNodes.RemoveAt(index); } }
//whether contain the key public bool ContainsKey(K _key) { int index = CQuickSort.Search <K>(mListKey, _key, CompareFunction); if (index >= 0) { return(true); } return(false); }
//try get value by key public bool TryGet(K _key, out T _value) { int index = CQuickSort.Search <K>(mListKey, _key, CompareFunction); if (index >= 0) { _value = mListValue[index]; return(true); } _value = default(T); return(false); }
public void ConnectNode(PathNode _a, PathNode _b) { int index = -1; if (CQuickSort.Search <PathNode>(_a.mLink, _b, SortPathNodeCompare) >= 0) { Debug.LogError("Error: Alread have node in link, Can't connect again."); return; } _a.mLink.Add(_b); _b.mLink.Add(_a); _a.mLinkID.Add(_b.mId); _b.mLinkID.Add(_a.mId); }
public void RemoveLog(MissionLog _log) { if (_log == null) { return; } int index = CQuickSort.Search <MissionLog>(mListMissionLog, _log, CompareLog); if (index >= 0) { mListMissionLog.RemoveAt(index); } }
//remove by key public bool Remove(K _key) { int index = CQuickSort.Search <K>(mListKey, _key, CompareFunction); if (index < 0) { throw new Exception("no key to remove, key:" + _key); return(false); } mListKey.RemoveAt(index); mListValue.RemoveAt(index); return(true); }
//add by key and value public bool Add(K _key, T _value) { int index = CQuickSort.Search <K>(mListKey, _key, CompareFunction); if (index >= 0) { throw new Exception("already have key " + _key); return(false); } index = CQuickSort.SearchInsert <K>(mListKey, _key, CompareFunction); if (index >= mListKey.Count) { mListKey.Add(_key); mListValue.Add(_value); } else { mListKey.Insert(index, _key); mListValue.Insert(index, _value); } return(true); }