コード例 #1
0
 internal static int HashUChar32(int h, int c)
 {
     h = Trie2.HashByte(h, c & 255);
     h = Trie2.HashByte(h, (c >> 8) & 255);
     h = Trie2.HashByte(h, c >> 16);
     return(h);
 }
コード例 #2
0
 /// <summary>
 /// Internal constructor.
 /// </summary>
 internal Trie2CharSequenceEnumerator(Trie2 trie2, ICharSequence t, int index)
 {
     this.trie2 = trie2;
     text       = t;
     textLength = text.Length;
     Set(index);
 }
コード例 #3
0
 internal static int HashInt(int h, int i)
 {
     h = Trie2.HashByte(h, i & 255);
     h = Trie2.HashByte(h, (i >> 8) & 255);
     h = Trie2.HashByte(h, (i >> 16) & 255);
     h = Trie2.HashByte(h, (i >> 24) & 255);
     return(h);
 }
コード例 #4
0
 // The normal constructor that configures the iterator to cover the complete
 //   contents of the Trie2
 internal Trie2Enumerator(Trie2 trie2, IValueMapper vm)
 {
     this.trie2       = trie2;
     mapper           = vm;
     nextStart        = 0;
     limitCP          = 0x110000;
     doLeadSurrogates = true;
 }
コード例 #5
0
        public override int GetHashCode()
        {
            int h = Trie2.InitHash();

            h = Trie2.HashUChar32(h, StartCodePoint);
            h = Trie2.HashUChar32(h, EndCodePoint);
            h = Trie2.HashInt(h, Value);
            h = Trie2.HashByte(h, IsLeadSurrogate ? 1 : 0);
            return(h);
        }
コード例 #6
0
 // An alternate constructor that configures the iterator to cover only the
 //   code points corresponding to a particular Lead Surrogate value.
 internal Trie2Enumerator(Trie2 trie2, char leadSurrogate, IValueMapper vm)
 {
     if (leadSurrogate < 0xd800 || leadSurrogate > 0xdbff)
     {
         throw new ArgumentException("Bad lead surrogate value.");
     }
     this.trie2       = trie2;
     mapper           = vm;
     nextStart        = (leadSurrogate - 0xd7c0) << 10;
     limitCP          = nextStart + 0x400;
     doLeadSurrogates = false;   // Do not iterate over lead the special lead surrogate
                                 //   values after completing iteration over code points.
 }
コード例 #7
0
        /// <summary>
        /// Equals function.  Two <see cref="Trie"/>s are equal if their contents are equal.
        /// The type need not be the same, so a <see cref="Trie2Writable"/> will be equal to
        /// (read-only) <see cref="Trie2_16"/> or <see cref="Trie2_32"/> so long as they are storing the same values.
        /// </summary>
        public override bool Equals(object other)
        {
            if (!(other is Trie2))
            {
                return(false);
            }
            Trie2      OtherTrie = (Trie2)other;
            Trie2Range rangeFromOther;

            using (var otherIter = OtherTrie.GetEnumerator())
            {
                foreach (Trie2Range rangeFromThis in this)
                {
                    if (otherIter.MoveNext() == false)
                    {
                        return(false);
                    }
                    rangeFromOther = otherIter.Current;
                    if (!rangeFromThis.Equals(rangeFromOther))
                    {
                        return(false);
                    }
                }
                if (otherIter.MoveNext())
                {
                    return(false);
                }
            }

            if (errorValue != OtherTrie.errorValue ||
                initialValue != OtherTrie.initialValue)
            {
                return(false);
            }

            return(true);
        }
コード例 #8
0
 /// <summary>
 /// Create a <see cref="Trie2"/> from its serialized form.  Inverse of utrie2_serialize().
 /// </summary>
 /// <remarks>
 /// The serialized format is identical between ICU4C, ICU4J, and ICU4N, so this function
 /// will work with serialized <see cref="Trie2"/>s from any.
 /// <para/>
 /// The serialized <see cref="Trie2"/> in the bytes may be in either little or big endian byte order.
 /// This allows using serialized Tries from ICU4C without needing to consider the
 /// byte order of the system that created them.
 /// </remarks>
 /// <param name="bytes">A byte buffer to the serialized form of a <see cref="Trie2"/>.</param>
 /// <returns>An unserialized <see cref="Trie2_32"/>, ready for use.</returns>
 /// <exception cref="System.ArgumentException">If the buffer does not contain a serialized <see cref="Trie2"/>.</exception>
 /// <exception cref="System.IO.IOException">If a read error occurs in the buffer.</exception>
 /// <exception cref="System.InvalidCastException">If the bytes contain a serialized <see cref="Trie2_16"/>.</exception>
 new public static Trie2_32 CreateFromSerialized(ByteBuffer bytes) // ICU4N TODO: API Create overload that accepts byte[]
 {
     return((Trie2_32)Trie2.CreateFromSerialized(bytes));
 }