public NodeEdges AddOrUpdate(NodeHandle n, NodeEdges newValue, Func <NodeHandle, NodeEdges, NodeEdges> valueFactory) { RegionHandle r = Region(n); recentRegions.AddOrUpdate(r, TotalTime.ElapsedMilliseconds); SetDirty(r); return(Regions.GetOrAdd(r, regionFactory).AddOrUpdate(n, newValue, valueFactory)); }
public void AddNode(Node node) { if (node.Graph != this || node.Index != NodeCount) { throw new InvalidOperationException(); } _nodes.Add(node); NodeEdges.Add(new List <Edge>()); }
public static IEnumerable <NodeHandle> Edges(NodeHandle a, NodeEdges e) { for (int i = 0; i < edgeOffsets.Length; i++) { if (e.HasFlag((NodeEdges)(1ul << i))) { yield return(AddEdgeOffset(a, i)); } } }
public void Set(NodeHandle n, NodeEdges e) { RegionHandle r = Region(n); Regions .GetOrAdd(r, regionFactory) .AddOrUpdate(n, e, (k, o) => e); recentRegions.AddOrUpdate(r, TotalTime.ElapsedMilliseconds); SetDirty(r); }
public static void PropagateClearance(Queue <NodeHandle> queue) { while (queue.TryDequeue(out NodeHandle n)) { NodeEdges nEdges = GetEdges(n); uint c = Clearance(nEdges); foreach (NodeHandle e in Edges(n, nEdges)) { uint d = Clearance(e); if (d == 0 || d > c + 1) { Clearance(e, c + 1); queue.Enqueue(e); } else if (d < c - 1) { Clearance(n, d + 1); queue.Enqueue(n); } } } }
public static NodeEdges Clearance(NodeEdges e, uint value) { var mask = (NodeEdges)((ulong)value << 32); return((e & ~NodeEdges.ClearanceMask) | mask); }
public static uint Clearance(NodeEdges e) => (uint)((ulong)(e & NodeEdges.ClearanceMask) >> 32);
public static bool IsCover(NodeHandle a) => HasFlag(a, NodeEdges.IsCover); // AllEdges.TryGetValue(a, out var flags) && (flags & NodeEdges.IsCover) > 0; public static NodeEdges IsCover(NodeEdges e, bool value) => value ? e | NodeEdges.IsCover : e & ~NodeEdges.IsCover;
public static NodeEdges IsGrown(NodeEdges e, bool value) => value ? e | NodeEdges.IsGrown : e & ~NodeEdges.IsGrown;
public static bool IsGrown(NodeEdges e) => e.HasFlag(NodeEdges.IsGrown);
public static void SetEdges(NodeHandle a, NodeEdges e) => AllNodes.Set(a, e);
public static NodeEdges AddEdge(NodeEdges e, NodeHandle a, NodeHandle b) { long d = (long)((ulong)b & handleMask) - (long)((ulong)a & handleMask); return(!whichEdgeBit.ContainsKey(d) ? e : e | (NodeEdges)(1ul << whichEdgeBit[d])); }
public static bool HasEdge(NodeEdges e, NodeHandle a, NodeHandle b) { long d = (long)((ulong)b & handleMask) - (long)((ulong)a & handleMask); return(whichEdgeBit.ContainsKey(d) ? e.HasFlag((NodeEdges)(1ul << whichEdgeBit[d])) : false); }
public static bool HasFlag(NodeHandle n, NodeEdges flag) => (AllNodes.Get(n) & flag) != 0;
public void AddNode() { _nodes.Add(NodeFactory.CreateNode(this, NodeCount)); NodeEdges.Add(new List <Edge>()); }