/// <summary> /// Ensures that the given name is in this set. /// </summary> public void Add(HierarchicalNameId name) { Contract.Requires(name.IsValid); if (m_added.TryAdd(name, Unit.Void)) { // TODO: Since we can atomically know the set of previous flags, it would be much nicer if we avoided // using m_added at all in the common case (i.e., only a single scheduler instance is using flags) Analysis.IgnoreResult(m_nameTable.SetFlags(name, m_memberFlags)); } }
private bool TryGetRootToken(HierarchicalNameId name, HierarchicalNameTable.NameFlags nameFlags, out string rootToken) { if (((nameFlags & HierarchicalNameTable.NameFlags.Root) == HierarchicalNameTable.NameFlags.Root) && m_roots.TryGetValue(name, out rootToken)) { return(true); } rootToken = null; return(false); }
/// <summary> /// Visits each name in the hierarchy from <paramref name="start"/> (bottom-up), and returns the first mapping found. /// </summary> public bool TryGetFirstMapping(HierarchicalNameId start, out KeyValuePair <HierarchicalNameId, TValue> mapping) { foreach (var currentMapping in EnumerateMappingsInHierarchyBottomUp(start)) { mapping = currentMapping; return(true); } mapping = default(KeyValuePair <HierarchicalNameId, TValue>); return(false); }
/// <summary> /// Adds a mapping from the given name to the given value, returning either the existing value or a newly added one. /// The semantics are the same as <see cref="ConcurrentDictionary{TKey,TValue}.GetOrAdd(TKey,System.Func{TKey,TValue})"/> /// </summary> public TValue GetOrAdd(HierarchicalNameId name, Func <HierarchicalNameId, TValue> valueFactory) { Contract.Requires(name.IsValid); TValue effectiveValue = m_map.GetOrAdd(name, valueFactory); // TODO: Since we can atomically know the set of previous flags, it would be much nicer if we avoided // using m_added at all in the common case (i.e., only a single scheduler instance is using flags) Analysis.IgnoreResult(m_nameTable.SetFlags(name, m_memberFlags)); return(effectiveValue); }
/// <summary> /// Finds the first name in the hierarchy of <paramref name="name" /> (bottom-up) that is in this set. /// If no match is found, <see cref="HierarchicalNameId.Invalid"/> is returned. /// </summary> public HierarchicalNameId FindInHierarchyBottomUp(HierarchicalNameId name) { foreach (HierarchicalNameId current in m_nameTable.EnumerateHierarchyBottomUp(name, flagsFilter: m_memberFlags)) { if (m_added.ContainsKey(current)) { return(current); } } return(HierarchicalNameId.Invalid); }
/// <inheritdoc /> public override int GetLength( HierarchicalNameId name, StringTable stringTable, StringId stringId, HierarchicalNameTable.NameFlags nameFlags, out bool expandContainer) { string rootToken; if (TryGetRootToken(name, nameFlags, out rootToken)) { expandContainer = false; return(rootToken.Length); } return(base.GetLength(name, stringTable, stringId, nameFlags, out expandContainer)); }
/// <inheritdoc /> public override int CopyString( HierarchicalNameId name, StringTable stringTable, StringId stringId, HierarchicalNameTable.NameFlags nameFlags, char[] buffer, int endIndex) { string rootToken; if (TryGetRootToken(name, nameFlags, out rootToken)) { rootToken.CopyTo(0, buffer, endIndex - rootToken.Length, rootToken.Length); return(rootToken.Length); } return(base.CopyString(name, stringTable, stringId, nameFlags, buffer, endIndex)); }
/// <summary> /// Creates an absolute identifier for some underlying integer value. /// </summary> /// <remarks> /// Since the value must have some meaning to a identifier table, this constructor should primarily be called by SymbolTables. /// The only other reasonable usage would be for temporary serialization (e.g. to a child process). /// </remarks> public FullSymbol(int value, char separator = default) { Value = new HierarchicalNameId(value); AlternateSeparator = separator; }
/// <summary> /// Creates an absolute identifier for some underlying HierchicalNameId value. /// </summary> /// <remarks> /// Since the value must have some meaning to a identifier table, this constructor should primarily be called by SymbolTables. /// The only other reasonable usage would be for temporary serialization (e.g. to a child process). /// </remarks> public FullSymbol(HierarchicalNameId value, char separator = default) { Value = value; AlternateSeparator = separator; }
/// <summary> /// Visits each name in the hierarchy from <paramref name="start"/> (bottom-up), and returns each mapping found. /// </summary> public BottomUpMappingEnumerator EnumerateMappingsInHierarchyBottomUp(HierarchicalNameId start) { return(new BottomUpMappingEnumerator(m_nameTable.EnumerateHierarchyBottomUp(start, flagsFilter: m_memberFlags), m_map)); }
public TValue this[HierarchicalNameId name] => m_map[name];
/// <summary> /// Creates an absolute identifier for some underlying integer value. /// </summary> /// <remarks> /// Since the value must have some meaning to a identifier table, this constructor should primarily be called by SymbolTables. /// The only other reasonable usage would be for temporary serialization (e.g. to a child process). /// </remarks> public FullSymbol(int value) { Value = new HierarchicalNameId(value); }
/// <summary> /// Creates an absolute identifier for some underlying HierchicalNameId value. /// </summary> /// <remarks> /// Since the value must have some meaning to a identifier table, this constructor should primarily be called by SymbolTables. /// The only other reasonable usage would be for temporary serialization (e.g. to a child process). /// </remarks> public FullSymbol(HierarchicalNameId value) { Value = value; }