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); }
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); }
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); }