public byte[] GetPixelData() { return(InternalResult.GetPixelData()); }
private static int FindChildMatch(XElement child, IList<XElement> possibleMatches, out InternalResult result) { result = new InternalResult(); for (var i = 0; i < possibleMatches.Count; ++i) { result = AreObjectsEqual(child, possibleMatches[i]); if (result.FailObject == null) return i; } return -1; }
private static int FindChildMatch(XElement child, IList <XElement> possibleMatches, out InternalResult result) { result = new InternalResult(); for (var i = 0; i < possibleMatches.Count; ++i) { result = AreObjectsEqual(child, possibleMatches[i]); if (result.FailObject == null) { return(i); } } return(-1); }
public override InternalResult <SourcePos> Parse(ref ParseState <TToken> state) => InternalResult.Success(state.ComputeSourcePos(), false);
internal List <Result> Calculate(IEnumerable <Camp> camps, IncomingResources incomingResourcesObject) { // Calculate total skills needed DateTime start = DateTime.Now; SortedDictionary <string, SkillWithCount> skills = new SortedDictionary <string, SkillWithCount>(); foreach (Camp camp in camps) { foreach (SkillWithCount campSkillWithCount in camp.Skills) { SkillWithCount skillWithCount = null; if (skills.TryGetValue(campSkillWithCount.Skill.Id, out skillWithCount)) { skillWithCount.Count += campSkillWithCount.Count; } else { skillWithCount = new SkillWithCount(campSkillWithCount.Skill, campSkillWithCount.Count); skills.Add(skillWithCount.Skill.Id, skillWithCount); } } } int[] skillCount = new int[skills.Count]; List <SkillWithCount> skillsWithCount = new List <SkillWithCount>(skills.Values); IDictionary <string, double> incomingResources = incomingResourcesObject.GetResources(); int MAX_RESULTS = 10; List <InternalResult> internalResults = new List <InternalResult>(MAX_RESULTS); SortedDictionary <string, BuffCountExpression> buffExpressions = PrepareBuffExpressions(skillsWithCount); SortedDictionary <string, ResourceCountExpression> resourceExpression = PrepareResourceExpressions(buffExpressions); SortedDictionary <string, ResourceInStorageExpression> resourceInStorageExpression = PrepareResourceInStorageExpressions(buffExpressions, incomingResources); TimeExpression timeExpression = new TimeExpression(); foreach (KeyValuePair <string, ResourceCountExpression> pair in resourceExpression) { timeExpression.Add(incomingResources[pair.Key], pair.Value); } TimeExpression timeStorageCostExpression = new TimeExpression(); foreach (KeyValuePair <string, ResourceInStorageExpression> pair in resourceInStorageExpression) { timeStorageCostExpression.Add(incomingResources[pair.Key], pair.Value); } double totalVariantCount = 1; foreach (SkillWithCount skill in skillsWithCount) { totalVariantCount *= skill.Count + 1; } int inc = 1; if (totalVariantCount > 10000000) { inc = 2; } if (totalVariantCount > 15000000) { inc = 3; } while (Inc(skillCount, skillsWithCount, inc)) { double time = timeExpression.Calculate(skillCount); if (internalResults.Count < MAX_RESULTS) { InternalResult newResult = new InternalResult(time, (int[])skillCount.Clone(), timeStorageCostExpression); AddResult(internalResults, newResult); } else if (time < internalResults[MAX_RESULTS - 1].Time) { internalResults.RemoveAt(MAX_RESULTS - 1); InternalResult newResult = new InternalResult(time, (int[])skillCount.Clone(), timeStorageCostExpression); AddResult(internalResults, newResult); } } if (inc > 1) { AdjastSolutions(skillsWithCount, internalResults, timeExpression); } return(PrepareResults(camps, skillsWithCount, internalResults, buffExpressions, resourceInStorageExpression)); }
public sealed override InternalResult <T> Parse(ref ParseState <TToken> state) => InternalResult.Success <T>(_value, false);
private InsertResult Insert(NodePin thisLock, TKey key, TValue value, NodePin parent, int parentIx) // where T : ICreateOrUpdateValue<TKey, TValue> { Node me = thisLock.Ptr; if (me.Count == me.Size && parent != null) { using (NodeTransaction trans = _storage.BeginTransaction()) { TKey splitAt; if (parent.Ptr.IsRoot) //Is root node { Node rootNode = trans.BeginUpdate(parent); using (NodePin newRoot = trans.Create(parent, false)) { rootNode.ReplaceChild(0, thisLock.Handle, newRoot.Handle); newRoot.Ptr.Insert(0, new Element(default(TKey), thisLock.Handle)); using (NodePin next = Split(trans, ref thisLock, newRoot, 0, out splitAt, false)) using (thisLock) { var watch = new Stopwatch(); trans.Commit(); watch.Start(); GC.KeepAlive(thisLock); GC.KeepAlive(next); watch.Stop(); if (watch.ElapsedMilliseconds > 10000 && LoggerManager.Instance.IndexLogger != null) { LoggerManager.Instance.IndexLogger.Debug("BPlusTree.Insert", "KeepAlive calls take: " + watch.ElapsedMilliseconds + " (ms)"); } } return(Insert(newRoot, key, value, parent, parentIx)); } } trans.BeginUpdate(parent); using (NodePin next = Split(trans, ref thisLock, parent, parentIx, out splitAt, false)) using (thisLock) { trans.Commit(); if (_keyComparer.Compare(key, splitAt) >= 0) { thisLock.Dispose(); return(Insert(next, key, value, parent, parentIx + 1)); } next.Dispose(); return(Insert(thisLock, key, value, parent, parentIx)); } } } if (parent != null) { parent.Dispose();//done with the parent lock. } int ordinal; if (me.BinarySearch(_itemComparer, new Element(key), out ordinal) && me.IsLeaf) { //TValue updatedValue = me[ordinal].Payload; //if (value.UpdateValue(key, ref updatedValue)) { using (NodeTransaction trans = _storage.BeginTransaction()) { me = trans.BeginUpdate(thisLock); InternalResult result = me.SetValue(ordinal, key, value, _keyComparer); if (_hasCount) { if (result == InternalResult.Added) { _keyCount++; _valueCount++; } else if (result == InternalResult.Updated) { _valueCount++; } } trans.UpdateValue(key, value); trans.Commit(); return(InsertResult.Updated); } } //return InsertResult.Exists; } if (me.IsLeaf) { //TValue newValue; //if (value.CreateValue(key, out newValue)) //{ using (NodeTransaction trans = _storage.BeginTransaction()) { me = trans.BeginUpdate(thisLock); me.Insert(ordinal, new Element(key, value)); _keyCount++; _valueCount++; trans.AddValue(key, value); trans.Commit(); return(InsertResult.Inserted); } //} //return InsertResult.NotFound; } if (ordinal >= me.Count) { ordinal = me.Count - 1; } using (NodePin child = _storage.Lock(thisLock, me[ordinal].ChildNode)) return(Insert(child, key, value, thisLock, ordinal)); }
private static Dictionary <string, int> GetRemainingSkills(List <SkillWithCount> skillsWithCount, InternalResult internalResult) { Dictionary <string, int> result = new Dictionary <string, int>(); for (int i = 0; i < skillsWithCount.Count; i++) { int j = 0; foreach (Buff buff in skillsWithCount[i].Skill.Buffs) { int count = internalResult.Solution[i]; if (j > 0) { count = skillsWithCount[i].Count - count; } result.Add(string.Format("{0}_{1}", skillsWithCount[i].Skill.Id, j), count); j++; } } return(result); }
public byte[] GetPixelData(out string photometricInterpretation) { return(InternalResult.GetPixelData(out photometricInterpretation)); }
internal static IResult <T> ToResult <T>(this InternalResult <T> result) { var warnings = new HashSet <string>(FromJava.IterableToEnumerable(result.getWarnings())); return(new SimpleResult <T>(result.getValue(), warnings)); }
internal override InternalResult <SourcePos> Parse(ref ParseState <TToken> state) => InternalResult.Success(state.SourcePos, false);
internal override InternalResult <int> Parse(ref ParseState <TToken> state) => InternalResult.Success(state.Location, false);
private int AddRange(NodePin thisLock, ref KeyRange range, AddRangeInfo value, NodePin parent, int parentIx) { int counter = 0; Node me = thisLock.Ptr; if (me.Count == me.Size && parent != null) { using (NodeTransaction trans = _storage.BeginTransaction()) { TKey splitAt; if (parent.Ptr.IsRoot) //Is root node { Node rootNode = trans.BeginUpdate(parent); using (NodePin newRoot = trans.Create(parent, false)) { rootNode.ReplaceChild(0, thisLock.Handle, newRoot.Handle); newRoot.Ptr.Insert(0, new Element(default(TKey), thisLock.Handle)); using (NodePin next = Split(trans, ref thisLock, newRoot, 0, out splitAt, true)) using (thisLock) { trans.Commit(); GC.KeepAlive(thisLock); GC.KeepAlive(next); } return(AddRange(newRoot, ref range, value, parent, parentIx)); } } trans.BeginUpdate(parent); using (NodePin next = Split(trans, ref thisLock, parent, parentIx, out splitAt, true)) using (thisLock) { trans.Commit(); if (_keyComparer.Compare(value.Current.Key, splitAt) >= 0) { thisLock.Dispose(); range.SetMinKey(splitAt); return(AddRange(next, ref range, value, parent, parentIx + 1)); } next.Dispose(); range.SetMaxKey(splitAt); return(AddRange(thisLock, ref range, value, parent, parentIx)); } } } if (parent != null) { parent.Dispose(); } if (me.IsLeaf) { using (NodeTransaction trans = _storage.BeginTransaction()) { me = trans.BeginUpdate(thisLock); int inserted = 0; while (me.Count < me.Size && !value.IsComplete && range.IsKeyInRange(value.Current.Key)) { int ordinal; bool exists = me.BinarySearch(_itemComparer, new Element(value.Current.Key), out ordinal); DuplicateKeyException.Assert(!exists || value.AllowUpdate); if (exists) { InternalResult result = me.SetValue(ordinal, value.Current.Key, value.Current.Value, _keyComparer); if (_hasCount) { if (result == InternalResult.Added) { _keyCount++; _valueCount++; } else if (result == InternalResult.Updated) { _valueCount++; } } trans.UpdateValue(value.Current.Key, value.Current.Value); } else { me.Insert(ordinal, new Element(value.Current.Key, value.Current.Value)); trans.AddValue(value.Current.Key, value.Current.Value); inserted++; } counter++; value.MoveNext(); } trans.Commit(); if (_hasCount && inserted > 0) { int count = _keyCount, test; while (count != (test = Interlocked.CompareExchange(ref _keyCount, count + inserted, count))) { count = test; } } } } else { int ordinal; me.BinarySearch(_itemComparer, new Element(value.Current.Key), out ordinal); if (ordinal >= me.Count) { ordinal = me.Count - 1; } if (ordinal > 0) { range.SetMinKey(me[ordinal - 1].Key); } if (ordinal < (me.Count - 1)) { range.SetMaxKey(me[ordinal + 1].Key); } using (NodePin child = _storage.Lock(thisLock, me[ordinal].ChildNode)) counter += AddRange(child, ref range, value, thisLock, ordinal); } return(counter); }