public ChecksumObject Add(ChecksumObject checksumObject) { // optimization to not create map. in whole solution level, there is // many case where green node is unique per checksum object such as metadata reference // or p2p reference. Interlocked.CompareExchange(ref _singleElementChecksumObject, checksumObject, null); if (_singleElementChecksumObject.Kind == checksumObject.Kind) { // we already have one Contract.Requires(_singleElementChecksumObject.Checksum.Equals(checksumObject.Checksum)); return(_singleElementChecksumObject); } // more expansive case. create map to save checksum object per kind EnsureLazyMap(); _lazyChecksumToChecksumObjectMap.TryAdd(checksumObject.Checksum, checksumObject); if (_lazyKindToChecksumObjectMap.TryAdd(checksumObject.Kind, checksumObject)) { // just added new one return(checksumObject); } // there is existing one. return(_lazyKindToChecksumObjectMap[checksumObject.Kind]); }
public ChecksumObject Add(ChecksumObject checksumObject) { Interlocked.CompareExchange(ref _checksumObject, checksumObject, null); // optimization to not create map. in whole solution level, there is // many case where green node is unique per checksum object such as metadata reference // or p2p reference. if (_checksumObject.Kind == checksumObject.Kind) { // we already have one Contract.Requires(_checksumObject.Checksum.Equals(checksumObject.Checksum)); return _checksumObject; } // more expansive case. create map to save checksum object per kind EnsureLazyMap(); _lazyChecksumToChecksumObjectMap.TryAdd(checksumObject.Checksum, checksumObject); if (_lazyKindToChecksumObjectMap.TryAdd(checksumObject.Kind, checksumObject)) { // just added new one return checksumObject; } // there is existing one. return _lazyKindToChecksumObjectMap[checksumObject.Kind]; }
public bool TryGetValue(string kind, out ChecksumObject checksumObject) { if (_checksumObject?.Kind == kind) { checksumObject = _checksumObject; return true; } if (_lazyKindToChecksumObjectMap != null) { return _lazyKindToChecksumObjectMap.TryGetValue(kind, out checksumObject); } checksumObject = null; return false; }
private ChecksumObject SaveAndReturn(object key, ChecksumObject checksumObject, ChecksumObjectCache entry = null) { // create new entry if it is not already given ChecksumObjectCache self; if (_cache.TryGetValue(key, out self)) { // we already have entry return(self.Add(checksumObject)); } // either create new entry or re-use given one. this will let us share // whole sub checksum tree that is associated with given green node (key) entry = _cache.GetOrAdd(key, _ => entry ?? new ChecksumObjectCache()); return(entry.Add(checksumObject)); }
public bool TryGetValue(Checksum checksum, out ChecksumObject checksumObject) { if (SingleElementChecksumObject?.Checksum == checksum) { checksumObject = SingleElementChecksumObject; return(true); } if (LazyChecksumToChecksumObjectMap != null) { return(LazyChecksumToChecksumObjectMap.TryGetValue(checksum, out checksumObject)); } checksumObject = null; return(false); }
public bool TryGetValue(string kind, out ChecksumObject checksumObject) { if (SingleElementChecksumObject?.Kind == kind) { checksumObject = SingleElementChecksumObject; return(true); } if (LazyKindToChecksumObjectMap != null) { return(LazyKindToChecksumObjectMap.TryGetValue(kind, out checksumObject)); } checksumObject = null; return(false); }
public bool TryGetValue(Checksum checksum, out ChecksumObject checksumObject) { if (_checksumObject?.Checksum == checksum) { checksumObject = _checksumObject; return true; } if (_lazyChecksumToChecksumObjectMap != null) { return _lazyChecksumToChecksumObjectMap.TryGetValue(checksum, out checksumObject); } checksumObject = null; return false; }
public ChecksumObjectCache(ChecksumObject checksumObject) { _checksumObject = checksumObject; }
public bool TryGetValue(Checksum checksum, out ChecksumObject checksumObject) { if (SingleElementChecksumObject?.Checksum == checksum) { checksumObject = SingleElementChecksumObject; return true; } if (LazyChecksumToChecksumObjectMap != null) { return LazyChecksumToChecksumObjectMap.TryGetValue(checksum, out checksumObject); } checksumObject = null; return false; }
private ChecksumObject SaveAndReturn(object key, ChecksumObject checksumObject, ChecksumObjectCache entry = null) { // create new entry if it is not already given entry = _cache.GetOrAdd(key, _ => entry ?? new ChecksumObjectCache(checksumObject)); return(entry.Add(checksumObject)); }