Exemplo n.º 1
0
        static MyStringId()
        {
            m_idByString = new Dictionary <string, MyStringId>(50);
            m_stringById = new Dictionary <MyStringId, string>(50, Comparer);

            NullOrEmpty = GetOrCompute("");
            Debug.Assert(NullOrEmpty == default(MyStringId));
            Debug.Assert(NullOrEmpty.m_id == MyUtils.GetHash(null, 0));
            Debug.Assert(NullOrEmpty.m_id == MyUtils.GetHash("", 0));
        }
Exemplo n.º 2
0
        static MyStringHash()
        {
            m_lock         = new FastResourceLock();
            m_stringToHash = new Dictionary <string, MyStringHash>(50);
            m_hashToString = new Dictionary <MyStringHash, string>(50, Comparer);

            NullOrEmpty = GetOrCompute("");
            Debug.Assert(NullOrEmpty == default(MyStringHash));
            Debug.Assert(NullOrEmpty.m_hash == MyUtils.GetHash(null, 0));
            Debug.Assert(NullOrEmpty.m_hash == MyUtils.GetHash("", 0));
        }
Exemplo n.º 3
0
        public static MyStringId GetOrCompute(string str)
        {
            MyStringId result;

            if (str == null)
            {
                result = NullOrEmpty;
            }
            else if (!m_idByString.TryGetValue(str, out result))
            {
                result = new MyStringId(MyUtils.GetHash(str, 0));
                m_stringById.Add(result, str);
                m_idByString.Add(str, result);
            }

            return(result);
        }
Exemplo n.º 4
0
        public static MyStringHash GetOrCompute(string str)
        {
            MyStringHash result;

            using (m_lock.AcquireExclusiveUsing())
            {
                if (str == null)
                {
                    result = NullOrEmpty;
                }
                else if (!m_stringToHash.TryGetValue(str, out result))
                {
                    result = new MyStringHash(MyUtils.GetHash(str, 0));
                    m_hashToString.Add(result, str);
                    m_stringToHash.Add(str, result);
                }
            }

            return(result);
        }