private static RangeToScan Build(Operator op, int firstSortedIndexWithValue, int lastSortedIndexWithValue, int count)
        {
            RangeToScan r = new RangeToScan();

            RangeToScan.TryBuild(op, firstSortedIndexWithValue, lastSortedIndexWithValue, count, ref r);
            return(r);
        }
Exemple #2
0
        public override void TryWhere(Operator op, T value, ShortSet result, ExecutionDetails details)
        {
            RangeToScan range   = new RangeToScan();
            bool        rangeOk = true;

            // For StartsWith, for ByteBlocks only, implement using IsPrefixOf
            if (op == Operator.StartsWith)
            {
                if (value is ByteBlock)
                {
                    IComparable <T> prefixComparer = (IComparable <T>)((ByteBlock)(object)value).GetExtendedIComparable(ByteBlock.Comparison.IsPrefixOf);     // trust me C#... I'm a professional...

                    int first = FindFirstWhere(prefixComparer);
                    int last  = FindLastWhere(prefixComparer);
                    if (!RangeToScan.TryBuild(Operator.Equals, first, last, this.Column.Count, ref range))
                    {
                        rangeOk = false;
                        if (details != null)
                        {
                            details.AddError(ExecutionDetails.ColumnDoesNotSupportOperator, op, this.Name);
                        }
                    }
                }
                else
                {
                    rangeOk = false;
                    if (details != null)
                    {
                        details.AddError(ExecutionDetails.ColumnDoesNotSupportOperator, op, this.Name);
                    }
                }
            }
            else
            {
                int first = FindFirstWhere(value);
                int last  = FindLastWhere(value);
                // Determine the range to scan to compute the result
                if (!RangeToScan.TryBuild(op, first, last, this.Column.Count, ref range))
                {
                    rangeOk = false;
                    if (details != null)
                    {
                        details.AddError(ExecutionDetails.ColumnDoesNotSupportOperator, op, this.Name);
                    }
                }
            }

            // Build the result set and return it
            if (rangeOk == true)
            {
                range.AddMatches(this.SortedIDs, result);
            }
        }
        private static string AddMatches(RangeToScan range, ushort[] sortedIDs, ushort[] previousValues)
        {
            ShortSet resultSet = new ShortSet((ushort)range.Count);

            // If previous values are specified, add them
            if (previousValues != null)
            {
                for (int i = 0; i < previousValues.Length; ++i)
                {
                    resultSet.Add(previousValues[i]);
                }
            }

            // Add matches for the range
            range.AddMatches(sortedIDs, resultSet);

            // Return the result as a string
            return(String.Join(", ", resultSet.Values));
        }