fillTo() public method

Pad the list with entries.
public fillTo ( int toIndex, int val ) : void
toIndex int index position to stop filling at. 0 inserts no filler. 1 ensures the list has a size of 1, adding val if the list is currently empty.
val int value to insert into padded positions.
return void
Ejemplo n.º 1
0
        /**
         * Index the region between <code>[ptr, end)</code> to find line starts.
         * <para />
         * The returned list is 1 indexed. Index 0 contains
         * {@link Integer#MIN_VALUE} to pad the list out.
         * <para />
         * Using a 1 indexed list means that line numbers can be directly accessed
         * from the list, so <code>list.get(1)</code> (aka get line 1) returns
         * <code>ptr</code>.
         * <para />
         * The last element (index <code>map.size()-1</code>) always contains
         * <code>end</code>.
         *
         * @param buf
         *            buffer to scan.
         * @param ptr
         *            position within the buffer corresponding to the first byte of
         *            line 1.
         * @param end
         *            1 past the end of the content within <code>buf</code>.
         * @return a line map indexing the start position of each line.
         */
        public static IntList lineMap(byte[] buf, int ptr, int end)
        {
            // Experimentally derived from multiple source repositories
            // the average number of bytes/line is 36. Its a rough guess
            // to initially size our map close to the target.
            //
            IntList map = new IntList((end - ptr) / 36);

            map.fillTo(1, int.MinValue);
            for (; ptr < end; ptr = nextLF(buf, ptr))
            {
                map.add(ptr);
            }
            map.add(end);
            return(map);
        }
Ejemplo n.º 2
0
 public void testFillTo100()
 {
     IntList i = new IntList();
     i.fillTo(100, int.MinValue);
     Assert.AreEqual(100, i.size());
     i.add(3);
     Assert.AreEqual(int.MinValue, i.get(99));
     Assert.AreEqual(3, i.get(100));
 }
Ejemplo n.º 3
0
 public void testFillTo1()
 {
     IntList i = new IntList();
     i.fillTo(1, int.MinValue);
     Assert.AreEqual(1, i.size());
     i.add(0);
     Assert.AreEqual(int.MinValue, i.get(0));
     Assert.AreEqual(0, i.get(1));
 }
Ejemplo n.º 4
0
 public void testFillTo0()
 {
     IntList i = new IntList();
     i.fillTo(0, int.MinValue);
     Assert.AreEqual(0, i.size());
 }
Ejemplo n.º 5
0
 /**
  * Index the region between <code>[ptr, end)</code> to find line starts.
  * <para />
  * The returned list is 1 indexed. Index 0 contains
  * {@link Integer#MIN_VALUE} to pad the list out.
  * <para />
  * Using a 1 indexed list means that line numbers can be directly accessed
  * from the list, so <code>list.get(1)</code> (aka get line 1) returns
  * <code>ptr</code>.
  * <para />
  * The last element (index <code>map.size()-1</code>) always contains
  * <code>end</code>.
  *
  * @param buf
  *            buffer to scan.
  * @param ptr
  *            position within the buffer corresponding to the first byte of
  *            line 1.
  * @param end
  *            1 past the end of the content within <code>buf</code>.
  * @return a line map indexing the start position of each line.
  */
 public static IntList lineMap(byte[] buf, int ptr, int end)
 {
     // Experimentally derived from multiple source repositories
     // the average number of bytes/line is 36. Its a rough guess
     // to initially size our map close to the target.
     //
     IntList map = new IntList((end - ptr) / 36);
     map.fillTo(1, int.MinValue);
     for (; ptr < end; ptr = nextLF(buf, ptr))
         map.add(ptr);
     map.add(end);
     return map;
 }