Exemplo n.º 1
0
        /// <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));
            }
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        /// <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);
        }
Exemplo n.º 6
0
        /// <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));
        }
Exemplo n.º 7
0
        /// <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));
        }
Exemplo n.º 8
0
 /// <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;
 }
Exemplo n.º 9
0
 /// <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;
 }
Exemplo n.º 10
0
 /// <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));
 }
Exemplo n.º 11
0
 public TValue this[HierarchicalNameId name] => m_map[name];
Exemplo n.º 12
0
 /// <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);
 }
Exemplo n.º 13
0
 /// <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;
 }