示例#1
0
        public override IntSet Complement(IntSet vocabulary0)
        {
            var vocabulary = vocabulary0 as IntervalIntSetBase;

            if (vocabulary == null)
            {
                throw new ArgumentException("Unsupported set type:" + vocabulary0, "vocabulary");
            }

            var result   = new IntervalIntSet(setType);
            Int previous = setType.MinValue;

            foreach (var interval in intervals)
            {
                if (interval.First != previous)
                {
                    var set = setType.Range(previous, interval.First - 1);
                    result.AddAll(set.Intersect(vocabulary));
                }

                previous = interval.Last + 1;
            }

            if (previous != setType.MaxValue)
            {
                var set = setType.Range(previous, setType.MaxValue);
                result.AddAll(set.Intersect(vocabulary));
            }

            result.UpdateHash();
            return(result);
        }
示例#2
0
        public override IntSet Intersect(IntSet other0)
        {
            IntervalIntSetBase other = (IntervalIntSetBase)other0;

            if (bounds.Intersects(other.bounds))
            {
                var result = new IntervalIntSet(setType);

                var otherIntervals = other.intervals;
                int myCount = intervals.Count;
                int theirCount = otherIntervals.Count;
                int i = 0, j = 0;

                while (i != myCount && j != theirCount)
                {
                    IntInterval mine   = intervals[i];
                    IntInterval theirs = otherIntervals[j];

                    switch (mine.RelationTo(theirs))
                    {
                    case IntIntervalRelation.Less:
                    {
                        ++i;
                        break;
                    }

                    case IntIntervalRelation.Greater:
                    {
                        ++j;
                        break;
                    }

                    case IntIntervalRelation.Equal:
                    case IntIntervalRelation.Contains:
                    {
                        result.Add(theirs);
                        ++j;
                        break;
                    }

                    case IntIntervalRelation.Contained:
                    {
                        result.Add(mine);
                        ++i;
                        break;
                    }

                    case IntIntervalRelation.OverlapFirst:
                    {
                        result.Add(mine * theirs);
                        ++i;
                        break;
                    }

                    case IntIntervalRelation.OverlapLast:
                    {
                        result.Add(mine * theirs);
                        ++j;
                        break;
                    }

                    default:
                        throw new InvalidOperationException("Internal error");
                    }
                }

                result.UpdateHash();
                return(result);
            }

            return(setType.Empty);
        }
        public override IntSet Intersect(IntSet other0)
        {
            IntervalIntSetBase other = (IntervalIntSetBase)other0;

            if (bounds.Intersects(other.bounds))
            {
                var result = new IntervalIntSet(setType);

                var otherIntervals = other.intervals;
                int myCount = intervals.Count;
                int theirCount = otherIntervals.Count;
                int i = 0, j = 0;

                while (i != myCount && j != theirCount)
                {
                    IntInterval mine = intervals[i];
                    IntInterval theirs = otherIntervals[j];

                    switch (mine.RelationTo(theirs))
                    {
                        case IntIntervalRelation.Less:
                        {
                            ++i;
                            break;
                        }
                        case IntIntervalRelation.Greater:
                        {
                            ++j;
                            break;
                        }
                        case IntIntervalRelation.Equal:
                        case IntIntervalRelation.Contains:
                        {
                            result.Add(theirs);
                            ++j;
                            break;
                        }
                        case IntIntervalRelation.Contained:
                        {
                            result.Add(mine);
                            ++i;
                            break;
                        }
                        case IntIntervalRelation.OverlapFirst:
                        {
                            result.Add(mine * theirs);
                            ++i;
                            break;
                        }
                        case IntIntervalRelation.OverlapLast:
                        {
                            result.Add(mine * theirs);
                            ++j;
                            break;
                        }
                        default:
                            throw new InvalidOperationException("Internal error");
                    }
                }

                result.UpdateHash();
                return result;
            }

            return setType.Empty;
        }
        public override IntSet Complement(IntSet vocabulary0)
        {
            var vocabulary = vocabulary0 as IntervalIntSetBase;
            if (vocabulary == null)
            {
                throw new ArgumentException("Unsupported set type:" + vocabulary0, "vocabulary");
            }

            var result = new IntervalIntSet(setType);
            Int previous = setType.MinValue;
            foreach (var interval in intervals)
            {
                if (interval.First != previous)
                {
                    var set = setType.Range(previous, interval.First - 1);
                    result.AddAll(set.Intersect(vocabulary));
                }

                previous = interval.Last + 1;
            }

            if (previous != setType.MaxValue)
            {
                var set = setType.Range(previous, setType.MaxValue);
                result.AddAll(set.Intersect(vocabulary));
            }

            result.UpdateHash();
            return result;
        }