/** * Marks all values since the last set as empty. The last set value is obtained from underlying * offsets vector. * * @param lastIndex the last index (inclusive) in the offsets vector until which empty population * takes place * @throws java.lang.IndexOutOfBoundsException if lastIndex is negative or greater than offsets * capacity. */ public void populate(int lastIndex) { if (lastIndex < 0) { throw new IndexOutOfBoundsException("index cannot be negative"); } final UInt4Vector.Accessor accessor = offsets.getAccessor(); final UInt4Vector.Mutator mutator = offsets.getMutator(); final int lastSet = Math.max(accessor.getValueCount() - 1, 0); final int previousEnd = accessor.get(lastSet); // 0 ? 0 : accessor.get(lastSet); for (int i = lastSet; i < lastIndex; i++) { mutator.setSafe(i + 1, previousEnd); } mutator.setValueCount(lastIndex + 1); }
@Test public void testFixedType() { final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE); // Create a new value vector for 1024 integers. try (final UInt4Vector vector = new UInt4Vector(field, allocator)) { final UInt4Vector.Mutator m = vector.getMutator(); vector.allocateNew(1024); // Put and set a few values m.setSafe(0, 100); m.setSafe(1, 101); m.setSafe(100, 102); m.setSafe(1022, 103); m.setSafe(1023, 104); final UInt4Vector.Accessor accessor = vector.getAccessor(); assertEquals(100, accessor.get(0)); assertEquals(101, accessor.get(1)); assertEquals(102, accessor.get(100)); assertEquals(103, accessor.get(1022)); assertEquals(104, accessor.get(1023)); } }