顺便把代码贴出来:

/** Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.** This code is free software; you can redistribute it and/or modify it* under the terms of the GNU General Public License version 2 only, as* published by the Free Software Foundation.  Oracle designates this* particular file as subject to the "Classpath" exception as provided* by Oracle in the LICENSE file that accompanied this code.** This code is distributed in the hope that it will be useful, but WITHOUT* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License* version 2 for more details (a copy is included in the LICENSE file that* accompanied this code).** You should have received a copy of the GNU General Public License version* 2 along with this work; if not, write to the Free Software Foundation,* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.** Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA* or visit www.oracle.com if you need additional information or have any* questions.*//** (C) Copyright Taligent, Inc. 1996,1997 - All Rights Reserved* (C) Copyright IBM Corp. 1996, 1997 - All Rights Reserved*/package sun.text;/** Simple internal class for doing hash mapping. Much, much faster than the* standard Hashtable for integer to integer mappings,* and doesn't require object creation.<br>* If a key is not found, the defaultValue is returned.* Note: the keys are limited to values above Integer.MIN_VALUE+1.<br>*/
public final class IntHashtable {public IntHashtable () {initialize(3);}public IntHashtable (int initialSize) {initialize(leastGreaterPrimeIndex((int)(initialSize/HIGH_WATER_FACTOR)));}public int size() {return count;}public boolean isEmpty() {return count == 0;}public void put(int key, int value) {if (count > highWaterMark) {rehash();}int index = find(key);if (keyList[index] <= MAX_UNUSED) {      // deleted or emptykeyList[index] = key;++count;}values[index] = value;                   // reset value}public int get(int key) {return values[find(key)];}public void remove(int key) {int index = find(key);if (keyList[index] > MAX_UNUSED) {       // neither deleted nor emptykeyList[index] = DELETED;            // set to deletedvalues[index] = defaultValue;        // set to default--count;if (count < lowWaterMark) {rehash();}}}public int getDefaultValue() {return defaultValue;}public void setDefaultValue(int newValue) {defaultValue = newValue;rehash();}public boolean equals (Object that) {if (that.getClass() != this.getClass()) return false;IntHashtable other = (IntHashtable) that;if (other.size() != count || other.defaultValue != defaultValue) {return false;}for (int i = 0; i < keyList.length; ++i) {int key = keyList[i];if (key > MAX_UNUSED && other.get(key) != values[i])return false;}return true;}public int hashCode() {// NOTE:  This function isn't actually used anywhere in this package, but it's here// in case this class is ever used to make sure we uphold the invariants about// hashCode() and equals()// WARNING:  This function hasn't undergone rigorous testing to make sure it actually// gives good distribution.  We've eyeballed the results, and they appear okay, but// you copy this algorithm (or these seed and multiplier values) at your own risk.//                                        --rtg 8/17/99int result = 465;   // an arbitrary seed valueint scrambler = 1362796821; // an arbitrary multiplier.for (int i = 0; i < keyList.length; ++i) {// this line just scrambles the bits as each value is added into the// has value.  This helps to make sure we affect all the bits and that// the same values in a different order will produce a different hash valueresult = result * scrambler + 1;result += keyList[i];}for (int i = 0; i < values.length; ++i) {result = result * scrambler + 1;result += values[i];}return result;}public Object clone ()throws CloneNotSupportedException {IntHashtable result = (IntHashtable) super.clone();values = values.clone();keyList = keyList.clone();return result;}// =======================PRIVATES============================private int defaultValue = 0;// the tables have to have prime-number lengths. Rather than compute// primes, we just keep a table, with the current index we are using.private int primeIndex;// highWaterFactor determines the maximum number of elements before// a rehash. Can be tuned for different performance/storage characteristics.private static final float HIGH_WATER_FACTOR = 0.4F;private int highWaterMark;// lowWaterFactor determines the minimum number of elements before// a rehash. Can be tuned for different performance/storage characteristics.private static final float LOW_WATER_FACTOR = 0.0F;private int lowWaterMark;private int count;// we use two arrays to minimize allocationsprivate int[] values;private int[] keyList;private static final int EMPTY   = Integer.MIN_VALUE;private static final int DELETED = EMPTY + 1;private static final int MAX_UNUSED = DELETED;private void initialize (int primeIndex) {if (primeIndex < 0) {primeIndex = 0;} else if (primeIndex >= PRIMES.length) {System.out.println("TOO BIG");primeIndex = PRIMES.length - 1;// throw new java.util.IllegalArgumentError();}this.primeIndex = primeIndex;int initialSize = PRIMES[primeIndex];values = new int[initialSize];keyList = new int[initialSize];for (int i = 0; i < initialSize; ++i) {keyList[i] = EMPTY;values[i] = defaultValue;}count = 0;lowWaterMark = (int)(initialSize * LOW_WATER_FACTOR);highWaterMark = (int)(initialSize * HIGH_WATER_FACTOR);}private void rehash() {int[] oldValues = values;int[] oldkeyList = keyList;int newPrimeIndex = primeIndex;if (count > highWaterMark) {++newPrimeIndex;} else if (count < lowWaterMark) {newPrimeIndex -= 2;}initialize(newPrimeIndex);for (int i = oldValues.length - 1; i >= 0; --i) {int key = oldkeyList[i];if (key > MAX_UNUSED) {putInternal(key, oldValues[i]);}}}public void putInternal (int key, int value) {int index = find(key);if (keyList[index] < MAX_UNUSED) {      // deleted or emptykeyList[index] = key;++count;}values[index] = value;                  // reset value}private int find (int key) {if (key <= MAX_UNUSED)throw new IllegalArgumentException("key can't be less than 0xFFFFFFFE");int firstDeleted = -1;  // assume invalid indexint index = (key ^ 0x4000000) % keyList.length;if (index < 0) index = -index; // positive onlyint jump = 0; // lazy evaluatewhile (true) {int tableHash = keyList[index];if (tableHash == key) {                 // quick checkreturn index;} else if (tableHash > MAX_UNUSED) {    // neither correct nor unused// ignore} else if (tableHash == EMPTY) {        // empty, end o' the lineif (firstDeleted >= 0) {index = firstDeleted;           // reset if had deleted slot}return index;} else if (firstDeleted < 0) {          // remember first deletedfirstDeleted = index;}if (jump == 0) {                        // lazy compute jumpjump = (key % (keyList.length - 1));if (jump < 0) jump = -jump;++jump;}index = (index + jump) % keyList.length;if (index == firstDeleted) {// We've searched all entries for the given key.return index;}}}private static int leastGreaterPrimeIndex(int source) {int i;for (i = 0; i < PRIMES.length; ++i) {if (source < PRIMES[i]) {break;}}return (i == 0) ? 0 : (i - 1);}// This list is the result of buildList below. Can be tuned for different// performance/storage characteristics.private static final int[] PRIMES = {17, 37, 67, 131, 257,521, 1031, 2053, 4099, 8209, 16411, 32771, 65537,131101, 262147, 524309, 1048583, 2097169, 4194319, 8388617, 16777259,33554467, 67108879, 134217757, 268435459, 536870923, 1073741827, 2147483647};
}

JDK自带的int值的sun.text.IntHashtable相关推荐

  1. java hprof 分析_[转]Sun JDK自带JVM内存使用分析工具HProf

    Sun JDK自带JVM内存使用分析工具HProf 2008-10-14 11:27 Sun JDK自带JVM内存使用分析工具HProf       使用Sun JDK自带JVM内存使用分析工具HPr ...

  2. Java将带小数点的String类型值转换成int值

    前言 今天在请求后台获取数据的时候,后台小哥给我挖了个坑 用到的数据是个int值 他给我返回个 String num = "29.00" 这样的字段 我去找他理论 他说:我后台不可 ...

  3. JVM系列(二):JDK自带监控命令

    为什么80%的码农都做不了架构师?>>>    当我们定位一个系统的问题时,知识.经验是关键基础,数据是依据,工具是运用知识处理数据的手段.这里的数据包括:运行日志.异常堆栈.GC日 ...

  4. 使用JDK自带的jmap和jhat监控处于运行状态的Java进程

    对于处于运行状态中的Java进程,JDK自带了很多工具,允许Java开发人员监控运行进程中的各种状态,比如该进程内部创建了多少个对象实例,消耗了多少内存,等等. 本文基于JDK1.8而写成. 我下面写 ...

  5. 使用了JDK自带的jconsole查看Tomcat运行情况

    最近对公司的项目进行JVM调优,使用了JDK自带的jconsole查看Tomcat运行情况,记录下配置以便以后参考: 首先,修改Tomcat的bin目录下的catalina.bat文件,在JAVA_O ...

  6. 利用jdk自带的运行监控工具JConsole观察分析Java程序的运行 Jtop

    利用jdk自带的运行监控工具JConsole观察分析Java程序的运行 原文链接 一.JConsole是什么 从Java 5开始 引入了 JConsole.JConsole 是一个内置 Java 性能 ...

  7. jvm调优 java_opt_Java-100天知识进阶-JVM调优工具-JDK自带工具-知识铺《八》

    原标题:Java-100天知识进阶-JVM调优工具-JDK自带工具-知识铺<八> JVM 监控分析工具 一.JDK 自带工具 1. jconsole JDK/bin 目录下, jconso ...

  8. jdk自带的jvm监控工具 jconsole ,jvisualvm,jmc

    1.jconsole jconsole 主要监控 JVM 的概览.内存.线程.类.vm概要.MBean等内容.JConsole 会消耗大量系统资源,因此 Oracle 建议仅在用于创建原型的开发环境中 ...

  9. 01、JUL日志(JDK自带日志框架,包含源码分析)

    文章目录 前言 一.JUL架构介绍 1.1.认识不同组件 1.2.Logger 1.3.Handler 二.输出日志信息 三.自定义日志级别配置 3.1.认识Level类 3.2.输出不同等级日志 3 ...

  10. 011 - JDK自带的性能监控工具

    一.概要: jps -l 查看现有的java进程 jps -l 显示所有正在运行的java进程id jstack 查看Java线程 jstack -l pid; 做thread dump,直接打印在串 ...

最新文章

  1. 使用函数对4*4的二维数组转置
  2. 使用脚本规范化企业office程序注册名
  3. python微信库wxpy_使用wxpy这个基于python实现的微信工具库的一些常见问题
  4. vue全局注册组件实例
  5. codeforces gym-101745 D-Stamp Stamp Stamp动态规划
  6. docker container
  7. 谷歌如何获取了我们的个人数据?
  8. 放弃Dubbo,选择最流行的Spring Cloud微服务架构实践与经验总结
  9. GALGAME文字提取agth 特殊码大全(特殊码表)和使用方法
  10. 关于TSP问题的几种解决办法
  11. 公交一卡通交通卡iphone“钱包”已有此卡无法添加的解决办法
  12. linux计划任务管理: cron定时任务,详解
  13. android ndk 如何安装,Android NDK 安装
  14. 未来大龄程序员出路有哪些?
  15. 创业不是 闹着玩的,水很深,
  16. 关于程序员的问题,我是看大佬说的不是我说的。
  17. IntelliJ IDEA 默认配置文件夹.IntelliJIdea在C盘,转移到其他盘符
  18. 牛逼的python代码_牛逼啊!一个随时随地写Python代码的神器
  19. HTML基础第十二讲---链接标志
  20. DX9光照效果-------VB6编程学习DX9游戏编程DirectX9编程2D小游戏源码冷风引擎CoolWind2D游戏引擎(12)

热门文章

  1. rbf神经网络_黄小龙,陈阳舟:高阶非线性不确定多智能体系统自适应RBF神经网络协同控制...
  2. html如何加入浮动客服,css如何实现客服悬浮效果
  3. android某个界面横屏,iOS强制某个界面横屏的方法
  4. csv反序列化_Py't'hon之csv,ini序列化,反序列化
  5. python plot 坐标轴范围_Python,Matplotlib,子图:如何设置轴范围?
  6. python中对象的定义_全面了解python中的类,对象,方法,属性
  7. android 获取emui版本,华为手机为什么有EMUI版本和Android版本?
  8. php var_dump和var_export区别
  9. jquery 添加扩展方法及为选择的对象添加方法
  10. 复利计算1.0,2.0,3.0(java)