1 /*-------------------------------------------------------------------------- 2 * Copyright 2010 utgenome.org 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 *--------------------------------------------------------------------------*/ 16 //-------------------------------------- 17 // utgb-core Project 18 // 19 // UInt32Array.java 20 // Since: 2010/11/05 21 // 22 //-------------------------------------- 23 package org.utgenome.util.aligner; 24 25 import java.util.ArrayList; 26 27 /** 28 * Array capable to store more than 2G (2 x 1024 x 1024 x 1024) entries 29 * 30 * @author leo 31 * 32 */ 33 public class LArray implements RandomAccess { 34 35 private final long size; 36 37 private ArrayList<int[]> array; 38 39 public LArray(long size) { 40 this.size = size; 41 42 // (flag)|---(array index)----|---------------------------| 43 // (flag)|------(31 bit)-------|------(index: 31bit)------| 44 int container = (int) (size >> 31); 45 int remainder = (int) size & 0x7FFFFFFF; 46 47 array = new ArrayList<int[]>(container + 1); 48 for (int i = 0; i < container; i++) { 49 array.add(new int[Integer.MAX_VALUE]); 50 } 51 if (remainder > 0) 52 array.add(new int[remainder]); 53 54 } 55 56 public long size() { 57 return size; 58 } 59 60 public int get(long index) { 61 int container = (int) (index >> 31); 62 int remainder = (int) index & 0x7FFFFFFF; 63 64 return array.get(container)[remainder]; 65 } 66 67 public void set(long index, int uintValue) { 68 int container = (int) (index >> 31); 69 int remainder = (int) index & 0x7FFFFFFF; 70 71 array.get(container)[remainder] = uintValue; 72 } 73 74 }