/// <summary> /// 将ValuedBitmapCollection按照val值从小到大排序 /// </summary> /// <param name="vpCollection">vbCollection</param> /// <returns></returns> public static ValuedBitmapCollection SortValuedBitmapCollection(ValuedBitmapCollection vbCollection) { if (vbCollection == null || vbCollection.Count == 0) { return(new ValuedBitmapCollection()); } int min; for (int i = 0; i < vbCollection.Count - 1; i++) { min = i; for (int j = i + 1; j < vbCollection.Count; j++) { if (((ValuedBitmap)vbCollection[j]).Val < ((ValuedBitmap)vbCollection[min]).Val) { min = j; } } ValuedBitmap t = (ValuedBitmap)vbCollection[min]; vbCollection[min] = vbCollection[i]; vbCollection[i] = t; } return(vbCollection); }
/// <summary> /// 初始化tld /// </summary> public Tld() { PosMapCollection = new ValuedBitmapCollection(); NegMapCollection = new ValuedBitmapCollection(); PosLength = 0; NegLength = 0; PosCenter = null; NegCenter = null; Dimension = 0; }
/// <summary> /// 在有序(val值从小到大)的ValuedBitmapCollection中插入ValuedBitmap,ValuedBitmapCollection中元素的数量 /// 不能超出limitedNumber,插入成功后返回集合元素数量 /// </summary> /// <param name="vbCollection">集合</param> /// <param name="vbmp">集合元素</param> /// <param name="limitedNumer">集合元素数量上限</param> /// <returns>返回是否插入成功</returns> public static bool InsertValuedBitmap(ref ValuedBitmapCollection vbCollection, ValuedBitmap vbmp, int limitedNumer) { ValuedBitmap tmpMap = null; bool hasinserted = false; // 返回值,是否已经插入 if (vbmp == null) { return(hasinserted); } if (vbCollection == null || vbCollection.Count == 0) { vbCollection = new ValuedBitmapCollection(); vbCollection.Add(vbmp); hasinserted = true; return(hasinserted); } for (int i = 0; i < vbCollection.Count; i++) { if (vbmp.Val < vbCollection[i].Val) { // 有新元素要插入,暂时保存队列最后一个元素,由limitedNumer来决定是否加入队列末尾 tmpMap = vbCollection[vbCollection.Count - 1]; for (int j = vbCollection.Count - 1; j > i; j--) { vbCollection[j] = vbCollection[j - 1]; } vbCollection[i] = vbmp; hasinserted = true; // 队列未满,可加入末尾 if (vbCollection.Count < limitedNumer) { vbCollection.Add(tmpMap); } break; } } if (!hasinserted && vbCollection.Count < limitedNumer) { vbCollection.Add(vbmp); hasinserted = true; } return(hasinserted); }