2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 package org.apache.lucene.analysis.compound.hyphenation;
21 import java.io.Serializable;
24 * This class implements a simple byte vector with access to the underlying
26 * This class has been taken from the Apache FOP project (http://xmlgraphics.apache.org/fop/). They have been slightly modified.
28 public class ByteVector implements Serializable {
31 * Capacity increment size
33 private static final int DEFAULT_BLOCK_SIZE = 2048;
35 private int blockSize;
38 * The encapsulated array
43 * Points to next free item
48 this(DEFAULT_BLOCK_SIZE);
51 public ByteVector(int capacity) {
55 blockSize = DEFAULT_BLOCK_SIZE;
57 array = new byte[blockSize];
61 public ByteVector(byte[] a) {
62 blockSize = DEFAULT_BLOCK_SIZE;
67 public ByteVector(byte[] a, int capacity) {
71 blockSize = DEFAULT_BLOCK_SIZE;
77 public byte[] getArray() {
82 * return number of items in array
89 * returns current capacity of array
91 public int capacity() {
95 public void put(int index, byte val) {
99 public byte get(int index) {
104 * This is to implement memory allocation in the array. Like malloc().
106 public int alloc(int size) {
108 int len = array.length;
109 if (n + size >= len) {
110 byte[] aux = new byte[len + blockSize];
111 System.arraycopy(array, 0, aux, 0, len);
118 public void trimToSize() {
119 if (n < array.length) {
120 byte[] aux = new byte[n];
121 System.arraycopy(array, 0, aux, 0, n);