public UniqueKeyDispatcher(params IUniqueKeyQuery <TItem>[] queries) : base(queries) { //MaxComparisons = 14; MaxComparisons = 22; State = new UniqueKeyQueryState(); }
public UniqueKeyQuery() { Root = new ReferenceNode <TItem, TKey>() { Values = new ValueNode <TItem> [0], Comparer = this.KeyComparer }; State = new UniqueKeyQueryState(); }
/// <summary> /// Creates a map with coordinates whether ephemeral or regular. /// </summary> /// <param name="self"></param> /// <param name="ephemeral">States that the coordinate for index will vanish after the first use</param> /// <returns></returns> public static Coordinates[] AcquireMap(this UniqueKeyQueryState self, bool ephemeral = false) { Func <Coordinates> getCoordinates = ephemeral ? (Func <Coordinates>) (() => new EphemeralCoordinates()) : () => new Coordinates(); var coordinates = new Coordinates[self.LevelCount]; for (int i = 0; i < self.LevelCount; i++) { coordinates[i] = getCoordinates(); } return(coordinates); }
private static int WorkAroundCSharpLimitations(UniqueKeyQueryState state, decimal percentageUsed, int i) { var value = decimal.Multiply( (decimal)Math.Pow(state.MaxLengthPerNode, i + 1), percentageUsed); var integerVal = (int)Math.Round(value); var lessThanZeroValue = Decimal.Subtract(value, integerVal); var factorOfCorrection = (decimal)(1 / Math.Pow(state.MaxLengthPerNode, i + 1)); return((int)(lessThanZeroValue >= factorOfCorrection ? Math.Ceiling(value) : integerVal)); }
public static UniqueKeyQueryState Calculate4UniqueKey(int totalLength, int maxComparisons) { if (totalLength == 4196352) { System.Diagnostics.Debugger.Break(); } var state = new UniqueKeyQueryState(); state.MaxIteractionsPerSegment = maxComparisons; state.MaxLengthPerNode = GetMaxLength(maxComparisons); state.LevelCount = CountLevels( totalLength, state.MaxLengthPerNode); Decimal percentageUsed = totalLength / (decimal)Math.Pow(state.MaxLengthPerNode, state.LevelCount); int i = 0; for (; i < state.LevelCount; i++) { state.Levels[i] = new UniqueKeyQueryState.Level { Index = i, TotalOfSpaces = (int)Math.Ceiling(Math.Pow(state.MaxLengthPerNode, i)), TotalUsed = WorkAroundCSharpLimitations(state, percentageUsed, i) }; } state.Levels[--i] = new UniqueKeyQueryState.Level { Index = i, TotalOfSpaces = (int)Math.Ceiling(Math.Pow(state.MaxLengthPerNode, i)), TotalUsed = totalLength }; return(state); }
protected override void SaveState() { this.State = this.NewState; }
protected override void DeriveNewState(OptimizedCollection <TItem> @struct) { NewState = UniqueKeyQueryCalculus.Calculate4UniqueKey(@struct.Count, MaxComparisons); }