📄 long_array.java
字号:
//-*-java-*-/*Copyright (c) 2003 Asoft ltd. All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of the authors may not be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY ANDFITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ASOFTLTD. OR ANY CONTRIBUTORS TO THIS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOTLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDINGNEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*//* *Copyright (c) 2003 Asoft ltd. All rights reserved. *www.asoft.ru *Authors: Alexandre Rusev, Alexey Soloviev */package com.asoft.midp.dynarray;import java.util.Vector;public final class long_array extends long_Array implements long_AccessibleArray{ private static final boolean FAST=true; private static final int DEBUG=1; private int block_size=500; private int len; private final long[][] arrays; private final int max_blocks; private final int residue; private int total_allocated; private String name; public long_array(int len){ this(len,500,null); } public long_array(int len, int block_size){ this(len,block_size,null); } public long_array(int len, String name){ this(len,500,name); } public long_array(int len, int block_size, String name){ this.block_size=block_size; this.len=len; this.name=name; if(this.block_size<=0){this.block_size=100;} this.block_size=Math.min(this.block_size,len); if(len>=0){ int n=this.len/this.block_size; residue=this.len-n*this.block_size; if(residue>0){++n;} max_blocks=n; arrays = new long[max_blocks][]; }else{ arrays = null; max_blocks=0; residue=0; }//if } public int length(){ return len; } public final int totalAllocated(){ return total_allocated; } public int blockSize(){ return block_size; } public final void set(int n, long val){ final int c=n/block_size; if(arrays[c]==null&&val!=0){ final int r=n%block_size; final int m; if(c==arrays.length-1&& this.residue>0){m=this.residue;}else{m=this.block_size;} arrays[c] = new long[m]; total_allocated=total_allocated+m; }//if(arrays[c]==null) if(arrays[c]!=null){ final int r=n%block_size; arrays[c][r]=val; }//if } public final long get(int n){ final int c=n/block_size; final int r=n%block_size; if(arrays[c]==null){ return 0; }else{ return arrays[c][r]; }//if(arrays[c]==null) } /**恨哓嚆这 刈 long[] src
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -