public void CommitTransaction(ChainBuilder chain, ImmutableSortedDictionary <UInt256, UnspentTx> .Builder unspentTransactions, ImmutableDictionary <int, IImmutableList <SpentTx> > .Builder blockSpentTxes, long chainVersion, long unspentTxesVersion, long blockSpentTxesVersion) { this.semaphore.Do(() => { if (chain != null && this.chainVersion != chainVersion || unspentTransactions != null && unspentTxesVersion != this.unspentTxesVersion || blockSpentTxes != null && blockSpentTxesVersion != this.blockSpentTxesVersion) { throw new InvalidOperationException(); } if (chain != null) { this.chain = chain.ToImmutable().ToBuilder(); this.chainVersion++; } if (unspentTransactions != null) { this.unspentTransactions = unspentTransactions.ToImmutable().ToBuilder(); this.unspentTxesVersion++; } if (blockSpentTxes != null) { this.blockSpentTxes = blockSpentTxes.ToImmutable().ToBuilder(); this.blockSpentTxesVersion++; } }); }
static void Main(string[] args) { ImmutableSortedDictionary <int, int> isd = ImmutableSortedDictionary.Create <int, int>(); isd = isd.Add(1, 1); isd = isd.Add(2, 2); isd = isd.Remove(2); ImmutableSortedDictionary <int, int> .Builder isdBuilder = isd.ToBuilder(); isdBuilder.Add(10, 10); //adds to original SortedDictionary. returns void. ImmutableSortedDictionary <int, int> .Builder builder = ImmutableSortedDictionary.CreateBuilder <int, int>(); builder.Add(3, 3); isd = builder.ToImmutable(); }
public static ImmutableSortedDictionary <string, HoistAction> RemoveCycles(ImmutableSortedDictionary <string, HoistAction> edges) { ImmutableSortedDictionary <string, HoistAction> .Builder builder = edges.ToBuilder(); foreach (KeyValuePair <string, HoistAction> currentEdge in edges) { string targetKey = FindCycle(builder, currentEdge); if (targetKey != null) { HoistAction nextKey; while (builder.TryGetValue(targetKey, out nextKey)) { builder.Remove(targetKey); targetKey = nextKey.Becomes; } } } return(builder.ToImmutable()); }
private static ImmutableSortedDictionary <string, HoistAction> GetViableHoistEdgeList(DataModel source) { ImmutableSortedDictionary <string, HoistAction> .Builder hoistMap = ImmutableSortedDictionary.CreateBuilder <string, HoistAction>(); foreach (DataModelType candidate in source.Types) { if (candidate.HasBase) { // Can't be hoist because this would break inheritance chains continue; } if (candidate.Members.Length != 1) { // Can't be hoist because the member can't replace the type continue; } DataModelMember toBe = candidate.Members[0]; hoistMap.Add(candidate.G4DeclaredName, new HoistAction(toBe.DeclaredName, toBe.Rank)); } return(hoistMap.ToImmutable()); }
public static ImmutableSortedDictionary <string, HoistAction> ApplyTransitiveProperty(ImmutableSortedDictionary <string, HoistAction> edges) { ImmutableSortedDictionary <string, HoistAction> .Builder builder = edges.ToBuilder(); var keys = new List <KeyValuePair <string, HoistAction> >(); foreach (string startingKey in edges.Keys) { keys.Clear(); string currentKey = startingKey; HoistAction currentValue; while (builder.TryGetValue(currentKey, out currentValue)) { keys.Add(Pair.Make(currentKey, currentValue)); currentKey = currentValue.Becomes; } Debug.Assert(keys.Count > 0); if (keys.Count <= 1) { // No transitive behavior to apply continue; } string becomes = keys[keys.Count - 1].Value.Becomes; int addedRanks = keys[keys.Count - 1].Value.AddedRanks; for (int idx = keys.Count - 2; idx >= 0; --idx) { KeyValuePair <string, HoistAction> key = keys[idx]; addedRanks += key.Value.AddedRanks; builder[key.Key] = new HoistAction(becomes, addedRanks); } } return(builder.ToImmutable()); }
protected override ImmutableSortedDictionary <TKey, TValue> Complete(ImmutableSortedDictionary <TKey, TValue> .Builder intermediateCollection) { return(intermediateCollection.ToImmutable()); }
public CompositeFactor(ImmutableSortedDictionary <int, int> .Builder factorsBuilder) { Factors = factorsBuilder.ToImmutable(); ApproxValue = Factors.Sum(k => k.Value * Math.Log(Primes.Values[k.Key])); }
protected override void Finalize(ImmutableSortedDictionary <TKey, TValue> .Builder builder, ref ImmutableSortedDictionary <TKey, TValue> collection) => collection = builder.ToImmutable();
public void CommitTransaction(ChainedHeader chainTip, int? unspentTxCount, int? unspentOutputCount, int? totalTxCount, int? totalInputCount, int? totalOutputCount, ImmutableSortedDictionary<UInt256, ChainedHeader>.Builder headers, ImmutableSortedDictionary<UInt256, UnspentTx>.Builder unspentTransactions, ImmutableDictionary<int, BlockSpentTxes>.Builder blockSpentTxes, ImmutableDictionary<UInt256, IImmutableList<UnmintedTx>>.Builder blockUnmintedTxes, long chainVersion, long unspentTxCountVersion, long unspentOutputCountVersion, long totalTxCountVersion, long totalInputCountVersion, long totalOutputCountVersion, long headersVersion, long unspentTxesVersion, long blockSpentTxesVersion, long blockUnmintedTxesVersion) { lock (this.lockObject) { if (chainTip != null && this.chainTipVersion != chainVersion || unspentTxCount != null && unspentTxCountVersion != this.unspentTxCountVersion || unspentOutputCount != null && unspentOutputCountVersion != this.unspentOutputCountVersion || totalTxCount != null && totalTxCountVersion != this.totalTxCountVersion || totalInputCount != null && totalInputCountVersion != this.totalInputCountVersion || totalOutputCount != null && totalOutputCountVersion != this.totalOutputCountVersion || headers != null && headersVersion != this.headersVersion || unspentTransactions != null && unspentTxesVersion != this.unspentTxesVersion || blockSpentTxes != null && blockSpentTxesVersion != this.blockSpentTxesVersion || blockUnmintedTxes != null && blockUnmintedTxesVersion != this.blockUnmintedTxesVersion) throw new InvalidOperationException(); if (chainTip != null) { this.chainTip = chainTip; this.chainTipVersion++; } if (unspentTxCount != null) { this.unspentTxCount = unspentTxCount.Value; this.unspentTxCountVersion++; } if (unspentOutputCount != null) { this.unspentOutputCount = unspentOutputCount.Value; this.unspentOutputCountVersion++; } if (totalTxCount != null) { this.totalTxCount = totalTxCount.Value; this.totalTxCountVersion++; } if (totalInputCount != null) { this.totalInputCount = totalInputCount.Value; this.totalInputCountVersion++; } if (totalOutputCount != null) { this.totalOutputCount = totalOutputCount.Value; this.totalOutputCountVersion++; } if (headers != null) { this.headers = headers.ToImmutable().ToBuilder(); this.headersVersion++; } if (unspentTransactions != null) { this.unspentTransactions = unspentTransactions.ToImmutable().ToBuilder(); this.unspentTxesVersion++; } if (blockSpentTxes != null) { this.blockSpentTxes = blockSpentTxes.ToImmutable().ToBuilder(); this.blockSpentTxesVersion++; } if (blockUnmintedTxes != null) { this.blockUnmintedTxes = blockUnmintedTxes.ToImmutable().ToBuilder(); this.blockUnmintedTxesVersion++; } } }