예제 #1
0
        public bool AddSource(XReference sourceReference)
        {
            if (_sourceToReference.ContainsKey(sourceReference))
            {
                return(false);
            }

            _referenceIndex = GetValidReferenceIndex(_referenceIndex + 1);
            _sourceToReference.Add(sourceReference, _referenceIndex);
            _referenceToSource.Add(_referenceIndex, sourceReference);
            return(true);
        }
예제 #2
0
        public long RemoveSource(XReference sourceReference)
        {
            long referenceId = -1;
            bool found       = _sourceToReference.TryGetValue(sourceReference, out referenceId);

            if (found)
            {
                _sourceToReference.Remove(sourceReference);
                _referenceToSource.Remove(referenceId);
            }

            return(referenceId);
        }
예제 #3
0
        public long GetFirstReferenceId(long startingIndex, out long requestId)
        {
            long referenceId = -1;
            long tries       = 0;

            requestId = -1;

            while (_referenceToSource.Count > 0) //if there are any items in the dictionary, we'll stop at the first entry we find.
            {
                referenceId = GetValidReferenceIndex(startingIndex + tries);
                XReference sourceReference = new XReference(requestId);

                if (_referenceToSource.TryGetValue(referenceId, out sourceReference))
                {
                    requestId = sourceReference.SourceId;
                    break;
                }

                tries++;
            }

            return(referenceId);
        }