private static byte[] GetMinMaxField(byte[] indexId, IItem item, FullDataIdFieldList fullDataIdFieldList) { // Note: Always place min value first followed by the max value in the return value int offset1 = fullDataIdFieldList[0].Offset; int offset2 = fullDataIdFieldList[1].Offset; byte[] fullDataIdField1 = GetFullDataIdField(indexId, item, fullDataIdFieldList[0]); byte[] fullDataIdField2 = GetFullDataIdField(indexId, item, fullDataIdFieldList[1]); byte[] retVal = new byte[fullDataIdFieldList[0].Count + fullDataIdFieldList[1].Count]; if (ByteArrayComparerUtil.CompareByteArrayBasedOnDataType(fullDataIdField1, fullDataIdField2, ref offset1, ref offset2, fullDataIdFieldList[0].Count, fullDataIdFieldList[1].Count, fullDataIdFieldList[0].DataType) < 0) { // FullDataIdField1 < FullDataIdField2 so FullDataIdField1 followed by FullDataIdField2 Array.Copy(fullDataIdField1, fullDataIdFieldList[0].Offset, retVal, 0, fullDataIdFieldList[0].Count); Array.Copy(fullDataIdField2, fullDataIdFieldList[1].Offset, retVal, fullDataIdFieldList[0].Count, fullDataIdFieldList[1].Count); } else { // FullDataIdField1 >= FullDataIdField2 so FullDataIdField2 followed by FullDataIdField1 Array.Copy(fullDataIdField2, fullDataIdFieldList[1].Offset, retVal, 0, fullDataIdFieldList[1].Count); Array.Copy(fullDataIdField1, fullDataIdFieldList[0].Offset, retVal, fullDataIdFieldList[1].Count, fullDataIdFieldList[0].Count); } return(retVal); }
/// <summary> /// Determines whether repositioning of index item is required or not. /// </summary> /// <param name="indexInfo">The index info.</param> /// <param name="addItem">The add item.</param> /// <param name="internalItem">The internal item.</param> /// <returns> /// <c>true</c> if repositioning of index item is required; otherwise, <c>false</c>. /// </returns> private static bool IsRepositioningOfIndexItemRequired(Index indexInfo, IndexDataItem addItem, InternalItem internalItem) { byte[] sortTagValueInAddItem; if (indexInfo.PrimarySortInfo.IsTag && addItem.Tags.TryGetValue(indexInfo.PrimarySortInfo.FieldName, out sortTagValueInAddItem)) { // Index is sorted by tag and tag might have been updated byte[] sortTagValueInIndex; internalItem.TryGetTagValue(indexInfo.PrimarySortInfo.FieldName, out sortTagValueInIndex); if (!ByteArrayComparerUtil.CompareByteArrays(sortTagValueInAddItem, sortTagValueInIndex)) { return(true); } } return(false); }
/// <summary> /// Linear searches the searchItem within the InternalItemList /// </summary> /// <param name="searchItem">The search item.</param> /// <param name="localIdentityTagNames">The local identity tag names.</param> /// <returns></returns> internal int LinearSearch(InternalItem searchItem, List <string> localIdentityTagNames) { try { for (int i = 0; i < Count; i++) { if (ByteArrayComparerUtil.CompareByteArrays(this[i].ItemId, searchItem.ItemId)) { if (EqualsLocalId(this[i], searchItem, localIdentityTagNames)) { return(i); } } } return(-1); } catch (Exception ex) { throw new Exception("Error in Linear Search.", ex); } }
/// <summary> /// Compares the specified arr1 to arr2. /// </summary> /// <param name="arr1">The arr1.</param> /// <param name="arr2">The arr2.</param> /// <returns></returns> public int Compare(byte[] arr1, byte[] arr2) { if (SortOrderList == null || SortOrderList.Count < 1) { if (Log.IsErrorEnabled) { Log.Error("Empty SortOrderList in BaseComparer"); } throw new Exception("Empty SortOrderList in BaseComparer"); } #region Null check for arrays if (arr1 == null || arr2 == null) { if (arr1 == null && arr2 == null) //Both arrays are null { return(0); } if (SortOrderList[0].SortBy == SortBy.ASC) //One of the arrays is null and order is ASC { if (arr1 == null) { return(-1); } return(1); } if (arr1 == null) //One of the arrays is null and order is DESC { return(1); } return(-1); } #endregion #region Length check for arrays if (arr1.Length != arr2.Length) { if (arr1.Length > arr2.Length) { return(1); } return(-1); } #endregion int retVal = 0; DataType dataType; startIndex1 = startIndex2 = 0; for (int i = 0; i < SortOrderList.Count && retVal == 0; i++) { dataType = SortOrderList[i].DataType; retVal = (SortOrderList[i].SortBy == SortBy.ASC) ? ByteArrayComparerUtil.CompareByteArrayBasedOnDataType(arr1, arr2, ref startIndex1, ref startIndex2, 0, 0, dataType) : ByteArrayComparerUtil.CompareByteArrayBasedOnDataType(arr2, arr1, ref startIndex2, ref startIndex1, 0, 0, dataType); } return(retVal); }