@@ -0,0 +1,1921 @@
+/*%0A * Copyright (c) 2013. Jordan Williams%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *    http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.jordanwilliams.heftydb.table.file;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0Apublic class IndexBuilder %7B%0A%0A    public interface Callback %7B%0A        public long writeIndexBlock(IndexBlock completed);%0A    %7D%0A%0A    private final Callback callback;%0A    private final List%3CIndexBlock.Builder%3E indexBlockBuilders = new ArrayList%3CIndexBlock.Builder%3E();%0A    private final int indexBlockSizeBytes;%0A%0A    public IndexBuilder(Callback callback, int indexBlockSizeBytes)%7B%0A        this.callback = callback;%0A        this.indexBlockSizeBytes = indexBlockSizeBytes;%0A    %7D%0A%0A    public void add(IndexBlock.Record record)%7B%0A        insert(record, 0);%0A    %7D%0A%0A    private void insert(IndexBlock.Record record, int level)%7B%0A        if (level == indexBlockBuilders.size())%7B%0A            indexBlockBuilders.add(new IndexBlock.Builder());%0A        %7D%0A%0A        IndexBlock.Builder builder = indexBlockBuilders.get(level);%0A%0A        if (builder.sizeBytes() %3E= indexBlockSizeBytes)%7B%0A            IndexBlock completed = builder.build();%0A            long offset = callback.writeIndexBlock(completed);%0A            insert(new IndexBlock.Record(completed.startKey(), offset), level++);%0A            builder = new IndexBlock.Builder();%0A            indexBlockBuilders.set(level, builder);%0A        %7D%0A%0A        builder.addRecord(record);%0A    %7D%0A%7D%0A

Add initial index builder