Ejemplo n.º 1
0
 private void BuildBytes(StringTrieBuilder.Option buildOption)
 {
     // Create and byte-serialize the trie for the elements.
     if (bytes == null)
     {
         bytes = new byte[1024];
     }
     BuildImpl(buildOption);
 }
Ejemplo n.º 2
0
 private void BuildChars(StringTrieBuilder.Option buildOption)
 {
     // Create and char-serialize the trie for the elements.
     if (chars == null)
     {
         chars = new char[1024];
     }
     BuildImpl(buildOption);
 }
Ejemplo n.º 3
0
        private void checkData(StringAndValue[] data, int dataLength, StringTrieBuilder.Option buildOption)
        {
            BytesTrie trie = buildTrie(data, dataLength, buildOption);

            checkFirst(trie, data, dataLength);
            checkNext(trie, data, dataLength);
            checkNextWithState(trie, data, dataLength);
            checkNextString(trie, data, dataLength);
            checkIterator(trie, data, dataLength);
        }
Ejemplo n.º 4
0
        private BytesTrie buildTrie(StringAndValue[] data, int dataLength,
                                    StringTrieBuilder.Option buildOption)
        {
            // Add the items to the trie builder in an interesting (not trivial, not random) order.
            int index, step;

            if ((dataLength & 1) != 0)
            {
                // Odd number of items.
                index = dataLength / 2;
                step  = 2;
            }
            else if ((dataLength % 3) != 0)
            {
                // Not a multiple of 3.
                index = dataLength / 5;
                step  = 3;
            }
            else
            {
                index = dataLength - 1;
                step  = -1;
            }
            builder_.Clear();
            for (int i = 0; i < dataLength; ++i)
            {
                builder_.Add(data[index].bytes, data[index].bytes.Length, data[index].value);
                index = (index + step) % dataLength;
            }
            BytesTrie trie = builder_.Build(buildOption);

            try
            {
                builder_.Add(/* "zzz" */ new byte[] { 0x7a, 0x7a, 0x7a }, 0, 999);
                Errln("builder.build().add(zzz) did not throw InvalidOperationException");
            }
            catch (InvalidOperationException e)
            {
                // good
            }
            ByteBuffer trieBytes = builder_.BuildByteBuffer(buildOption);

            Logln("serialized trie size: " + trieBytes.Remaining + " bytes\n");
            // Tries from either build() method should be identical but
            // BytesTrie does not implement equals().
            // We just return either one.
            if ((dataLength & 1) != 0)
            {
                return(trie);
            }
            else
            {
                return(new BytesTrie(trieBytes.Array, trieBytes.ArrayOffset + trieBytes.Position));
            }
        }
Ejemplo n.º 5
0
        private CharsTrie buildTrie(StringAndValue[] data, int dataLength,
                                    StringTrieBuilder.Option buildOption)
        {
            // Add the items to the trie builder in an interesting (not trivial, not random) order.
            int index, step;

            if ((dataLength & 1) != 0)
            {
                // Odd number of items.
                index = dataLength / 2;
                step  = 2;
            }
            else if ((dataLength % 3) != 0)
            {
                // Not a multiple of 3.
                index = dataLength / 5;
                step  = 3;
            }
            else
            {
                index = dataLength - 1;
                step  = -1;
            }
            builder_.Clear();
            for (int i = 0; i < dataLength; ++i)
            {
                builder_.Add(data[index].s, data[index].value);
                index = (index + step) % dataLength;
            }
            CharsTrie trie = builder_.Build(buildOption);

            try
            {
                builder_.Add("zzz", 999);
                Errln("builder.Build().Add(zzz) did not throw IllegalStateException");
            }
            catch (InvalidOperationException e)
            {
                // good
            }
            ICharSequence trieChars = builder_.BuildCharSequence(buildOption);

            Logln("serialized trie size: " + trieChars.Length + " chars");
            // Tries from either build() method should be identical but
            // CharsTrie does not implement equals().
            // We just return either one.
            if ((dataLength & 1) != 0)
            {
                return(trie);
            }
            else
            {
                return(new CharsTrie(trieChars, 0));
            }
        }
Ejemplo n.º 6
0
        private void BuildBytes(StringTrieBuilder.Option buildOption)
        {
            // Create and byte-serialize the trie for the elements.
            if (bytes == null)
            {
                bytes = new byte[1024];
            }
#pragma warning disable 612, 618
            BuildImpl(buildOption);
#pragma warning restore 612, 618
        }
Ejemplo n.º 7
0
        private void BuildChars(StringTrieBuilder.Option buildOption)
        {
            // Create and char-serialize the trie for the elements.
            if (chars == null)
            {
                chars = new char[1024];
            }
#pragma warning disable 612, 618
            BuildImpl(buildOption);
#pragma warning restore 612, 618
        }
Ejemplo n.º 8
0
 public BytesTrie buildMonthsTrie(StringTrieBuilder.Option buildOption)
 {
     // All types of nodes leading to the same value,
     // for code coverage of recursive functions.
     // In particular, we need a lot of branches on some single level
     // to exercise a split-branch node.
     StringAndValue[] data =
     {
         new StringAndValue("august",                          8),
         new StringAndValue("jan",                             1),
         new StringAndValue("jan.",                            1),
         new StringAndValue("jana",                            1),
         new StringAndValue("janbb",                           1),
         new StringAndValue("janc",                            1),
         new StringAndValue("janddd",                          1),
         new StringAndValue("janee",                           1),
         new StringAndValue("janef",                           1),
         new StringAndValue("janf",                            1),
         new StringAndValue("jangg",                           1),
         new StringAndValue("janh",                            1),
         new StringAndValue("janiiii",                         1),
         new StringAndValue("janj",                            1),
         new StringAndValue("jankk",                           1),
         new StringAndValue("jankl",                           1),
         new StringAndValue("jankmm",                          1),
         new StringAndValue("janl",                            1),
         new StringAndValue("janm",                            1),
         new StringAndValue("jannnnnnnnnnnnnnnnnnnnnnnnnnnnn", 1),
         new StringAndValue("jano",                            1),
         new StringAndValue("janpp",                           1),
         new StringAndValue("janqqq",                          1),
         new StringAndValue("janr",                            1),
         new StringAndValue("januar",                          1),
         new StringAndValue("january",                         1),
         new StringAndValue("july",                            7),
         new StringAndValue("jun",                             6),
         new StringAndValue("jun.",                            6),
         new StringAndValue("june", 6)
     };
     return(buildTrie(data, data.Length, buildOption));
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Builds a <see cref="BytesTrie"/> for the <see cref="Add(byte[], int, int)"/> appended data.
 /// Once built, no further data can be added until <see cref="Clear()"/> is called.
 ///
 /// <para/>A <see cref="BytesTrie"/> cannot be empty. At least one (byte sequence, value) pair
 /// must have been added.
 ///
 /// <para/>Multiple calls to <see cref="Build(Option)"/> or <see cref="BuildByteBuffer(Option)"/> return tries or buffers
 /// which share the builder's byte array, without rebuilding.
 /// <em>The byte array must not be modified via the <see cref="BuildByteBuffer(Option)"/> result object.</em>
 /// After <see cref="Clear()"/> has been called, a new array will be used.
 /// </summary>
 /// <param name="buildOption">Build option, see <see cref="StringTrieBuilder.Option"/>.</param>
 /// <returns> A new <see cref="BytesTrie"/> for the added data.</returns>
 /// <stable>ICU 4.8</stable>
 public BytesTrie Build(StringTrieBuilder.Option buildOption)
 {
     BuildBytes(buildOption);
     return(new BytesTrie(bytes, bytes.Length - bytesLength));
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Builds a <see cref="BytesTrie"/> for the <see cref="Add(byte[], int, int)"/> appended data and byte-serializes it.
 /// Once built, no further data can be added until <see cref="Clear()"/> is called.
 /// <para/>A <see cref="BytesTrie"/> cannot be empty. At least one (byte sequence, value) pair
 /// must have been added.
 ///
 /// <para/>Multiple calls to <see cref="Build(Option)"/> or <see cref="BuildByteBuffer(Option)"/> return tries or buffers
 /// which share the builder's byte array, without rebuilding.
 /// <em>Do not modify the bytes in the buffer!</em>
 /// After <see cref="Clear()"/> has been called, a new array will be used.
 ///
 /// <para/>The serialized <see cref="BytesTrie"/> is accessible via the buffer's
 /// <see cref="ByteBuffer.Array"/>/<see cref="ByteBuffer.ArrayOffset"/>+Position or Remaining/Get(byte[]) etc.
 /// </summary>
 /// <param name="buildOption">Build option, see <see cref="StringTrieBuilder.Option"/>.</param>
 /// <returns>A <see cref="ByteBuffer"/> with the byte-serialized <see cref="BytesTrie"/> for the added data.
 /// The buffer is not read-only and <see cref="ByteBuffer.Array"/> can be called.</returns>
 /// <stable>ICU 4.8</stable>
 public ByteBuffer BuildByteBuffer(StringTrieBuilder.Option buildOption)
 {
     BuildBytes(buildOption);
     return(ByteBuffer.Wrap(bytes, bytes.Length - bytesLength, bytesLength));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Builds a <see cref="CharsTrie"/> for the <see cref="Add(string, int)"/>ed data and char-serializes it.
 /// Once built, no further data can be <see cref="Add(string, int)"/>ed until <see cref="Clear()"/> is called.
 /// </summary>
 /// <remarks>
 /// A <see cref="CharsTrie"/> cannot be empty. At least one (string, value) pair
 /// must have been <see cref="Add(string, int)"/>ed.
 /// <para/>
 /// Multiple calls to <see cref="Build(Option)"/> or <see cref="BuildCharSequence(Option)"/> return tries or sequences
 /// which share the builder's char array, without rebuilding.
 /// After <see cref="Clear()"/> has been called, a new array will be used.
 /// </remarks>
 /// <param name="buildOption">Build option, see <see cref="StringTrieBuilder.Option"/>.</param>
 /// <returns>A <see cref="ICharSequence"/> with the char-serialized <see cref="CharsTrie"/> for the <see cref="Add(string, int)"/>ed data.</returns>
 /// <stable>ICU 4.8</stable>
 public ICharSequence BuildCharSequence(StringTrieBuilder.Option buildOption)
 {
     BuildChars(buildOption);
     return(CharBuffer.Wrap(chars, chars.Length - charsLength, charsLength));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Builds a <see cref="CharsTrie"/> for the <see cref="Add(string, int)"/>ed data.
 /// Once built, no further data can be <see cref="Add(string, int)"/>ed until <see cref="Clear()"/> is called.
 /// </summary>
 /// <remarks>
 /// A <see cref="CharsTrie"/> cannot be empty. At least one (string, value) pair
 /// must have been <see cref="Add(string, int)"/>ed.
 /// <para/>
 /// Multiple calls to <see cref="Build(Option)"/> or <see cref="BuildCharSequence(Option)"/> return tries or sequences
 /// which share the builder's char array, without rebuilding.
 /// After <see cref="Clear()"/> has been called, a new array will be used.
 /// </remarks>
 /// <param name="buildOption">Build option, see <see cref="StringTrieBuilder.Option"/>.</param>
 /// <returns>A new <see cref="CharsTrie"/> for the <see cref="Add(string, int)"/>ed data.</returns>
 /// <stable>ICU 4.8</stable>
 public CharsTrie Build(StringTrieBuilder.Option buildOption)
 {
     return(new CharsTrie(BuildCharSequence(buildOption), 0));
 }