- 浏览: 194461 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
only_java:
博主,你好。感谢这篇你的这篇文章,我的问题是跟你一样,也是在跑 ...
JVM Crash分析 -
shuofenglxy:
1 确保程序运行时没有更新程序需要的相关jar包。2 确保程序 ...
JVM Crash分析 -
renduly:
# A fatal error has been detect ...
JVM Crash分析 -
shuofenglxy:
renduly 写道博主好。这两天我在公司程序也出现了类似的问 ...
JVM Crash分析 -
renduly:
博主好。这两天我在公司程序也出现了类似的问题。博主能否说的详细 ...
JVM Crash分析
原文来自: http://wuhua.iteye.com/blog/394023
his
article illustrates how to implement an ordered hashtable, which maps
keys to values. Any non-null object can be used as a key or as a value.
As
with typical Hashtables, to successfully store and retrieve objects
from a hashtable, the objects used as keys must implement the hashCode
method and the equals method.
There
are many instances where you would like to use an ordered Hashtable,
for example, to keep your user interface elements ordered, or to keep
ordered items from a database or backend while keeping rapid access via
Hashtable keys, or to store and access any value you want to access
using a key.
This
ordered Hashtable is called simple because internally it uses the Legacy
collection classes, a Vector to maintain the element's order and a
Hashtable to provide hashing capabilities. Because Hashtable and Vector
grow differently, the implementation of
[edit]
A Hashtable implementation
SimpleOrderedHashtable is not the most efficient one, but may be good enough for your needs.
/* -----------------------------------------------------------------------------
* SimpleOrderedHashtable.java
* Author: C. Enrique Ortiz
* Copyright (c) 2004-2009 C. Enrique Ortiz <eortiz@j2medeveloper.com>
*
* SimpleOrderedHashtable.java implements a simple Hashtable that is
* chronologically ordered.
*
* This is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option) any
* later version.
*
* Usage & redistributions of source code must retain the above copyright notice.
*
* This software 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
* Lesser General Public License for more details.
*
* You should get a copy of the GNU Lesser General Public License from
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
* -----------------------------------------------------------------------------
*/
import java.util.Vector;
import java.util.Enumeration;
import java.util.Hashtable;
/**
* Implements an Ordered Hashtable, with elements in
* chronological order (i.e. insertion order)
*/
public class SimpleOrderedHashtable {
private Vector orderedKeys;
private Hashtable hashTable;
/**
* Constructor, creates an SimpleOrderedHashtable.
*/
public SimpleOrderedHashtable() {
orderedKeys = new Vector();
hashTable = new Hashtable();
}
/**
* Constructor, creates an SimpleOrderedHashtable.
* @param initialCapacity is the initial size for the container.
*/
public SimpleOrderedHashtable(int initialCapacity) {
orderedKeys = new Vector(initialCapacity);
hashTable = new Hashtable(initialCapacity);
}
/**
* Maps the specified key to the specified value in this SimpleOrderedHashtable.
* The value can be retrieved by calling the get method with a key that is
* equal to the original key.
* @param key is the hashtable key.
* @param value is the value.
* @return the previous value of the specified key in this
* SimpleOrderedHashtable, or null if it did not have one.
*/
synchronized public Object put(Object key, Object value) {
int i = orderedKeys.indexOf(key);
if (i == -1) {
// Add new name/value pair.
orderedKeys.addElement(key); // insert (append) to the end of the list
} else {
// Replace name/value pair.
orderedKeys.setElementAt(key, i);
}
return hashTable.put(key, value);
}
/**
* Returns the value to which the specified key is mapped in this
* hashtable.
* @param key is a key in the SimpleOrderedHashtable.
* @return the value to which the key is mapped in this hashtable; null if
* the key is not mapped to any value in this hashtable.
*/
synchronized public Object get(Object key) {
return hashTable.get(key);
}
/**
* Returns an enumeration of the keys in this SimpleOrderedHashtable.
* @return an enumeration of the keys in this SimpleOrderedHashtable.
*/
synchronized public Enumeration keys() {
return orderedKeys.elements();
}
/**
* Returns an enumeration of the elements in this SimpleOrderedHashtable.
* @return an enumeration of the elements in this SimpleOrderedHashtable.
*/
synchronized public Enumeration elements() {
int s = hashTable.size();
Vector elements = new Vector(s);
for (int i=0; i<s; i++) {
elements.addElement(elementAt(i));
}
return elements.elements();
}
/**
* Returns the component at the specified index.
* @param index is an index into this SimpleOrderedHashtable.
* @return the <code>Object</code> component at the specified index.
* @throws ArrayIndexOutOfBoundsException if index is out of bounds.
*/
synchronized public Object elementAt(int index)
throws ArrayIndexOutOfBoundsException {
Object key = orderedKeys.elementAt(index);
return hashTable.get(key);
}
/**
* Returns the key at the specified index.
* @param index is an index into this SimpleOrderedHashtable.
* @return the <code>Object</code> key at the specified index.
* @throws ArrayIndexOutOfBoundsException if index is out of bounds.
*/
synchronized public Object keyAt(int index)
throws ArrayIndexOutOfBoundsException {
return orderedKeys.elementAt(index);
}
/**
* Returns the index of the specified <code>Object</code>.
* @param key is a key in the SimpleOrderedHashtable.
* @return the index of the specified <code>Object</code>.
*/
synchronized public int getIndex(Object key) {
return orderedKeys.indexOf(key);
}
/**
* Removes the key (and its corresponding value) from this hashtable. This
* method does nothing if the key is not in the hashtable.
* @param key is the key that needs to be removed.
*/
synchronized public void remove(Object key) {
orderedKeys.removeElement(key);
hashTable.remove(key);
}
/**
* Removes an element at the specified index.
* @param i is the index of the element to remove.
*/
synchronized public void removeElementAt(int i) {
Object key = orderedKeys.elementAt(i);
orderedKeys.removeElementAt(i);
hashTable.remove(key);
}
/**
* Clears this SimpleOrderedHashtable so that it contains no keys.
*/
synchronized public void clear() {
orderedKeys.removeAllElements();
hashTable.clear();
}
/**
* Returns the number of components in this SimpleOrderedHashtable.
* @return the number of components in this vector.
*/
synchronized public int size() {
return orderedKeys.size();
}
/**
* Recomputes the SimpleOrderedHashtable capacity.
* @param capacity is the capacity to ensure.
*/
synchronized public void ensureCapacity(int capacity) {
orderedKeys.ensureCapacity(capacity);
}
}
发表评论
-
数组查值
2011-09-27 16:42 811问题描述:{4,5,7,8,1,2} 找值为K的元素。 两种 ... -
全排列 递归式
2011-09-27 15:18 866简单的整理一下全排列思路。全部遍历,打印前筛选条件。全部遍历则 ... -
简单的四则运算计算器
2011-09-27 11:27 868这是一个简单的四则运算计算器,不支持括号,没有做乘法的越 ... -
ZZ并查集
2011-02-22 15:40 888原文出处:http://blog.si ... -
ZZ那些优雅的数据结构(1) : BloomFilter——大规模数据处理利器
2011-02-21 14:39 1092原文来自:http://www.cnblogs.com/hea ... -
矩阵链乘法算法讲解
2011-02-15 15:57 4359矩阵链乘是一个计算 ... -
把二元查找树转变成排序的双向链表
2011-02-14 19:59 2007分析:二叉树中序遍历即可得到一个有序的结果,只要按照中序遍历的 ... -
递归总结二 汉诺塔问题
2011-02-07 19:38 1127汉诺塔是貌似递归入门的引导题目,把这个过程写下来,mark一下 ... -
递归总结一 全排列问题
2011-02-07 18:48 1570全排列问题:这是描述 ... -
几种常见的排序算法
2011-02-05 13:19 1137这里是以前写的算法总结了。照搬过来而已。 package S ... -
二叉树和红黑树的java实现
2011-02-05 13:11 1600二叉查找树代码大致如下: 二叉树节点类: pa ... -
LIS 最长递增子序列算法总结
2011-02-05 12:53 1483这里包含了三种求得递增子序列的算法。 是以前写的代码,这里就 ... -
求1的个数问题
2011-01-25 16:14 1143又是一年笔试时,很多学弟们开始笔试了。今天学弟问求一个int数 ... -
消除递归典型应用2------N阶台阶问题
2011-01-25 16:12 1384问题描述:一个人可以一步走1或2或3级台阶,问到N级台阶共有多 ... -
左右手法则的典型应用---字符串逆序
2011-01-25 16:10 1177问题:输入 I am a boy 输出boy a am I ... -
一个正整数拆分为连续的几个整数之和
2011-01-25 16:08 2594import java.util.Scanner; pu ... -
斐波那契序列的基本实现
2011-01-25 16:07 1669今天实在没事干,刚好别人问了我下斐波那契面试怎么回答。就 ... -
矩阵型数据 顺时针打印
2011-01-25 15:28 1411输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字。 ...
相关推荐
Java中的`Ordered`接口主要用在需要定义顺序或者排列规则的场景,特别是在Spring框架中,它在Bean的初始化和销毁顺序、AOP切面的执行顺序等方面起到关键作用。`Ordered`接口仅包含一个方法`getOrder()`,返回一个...
标题中的"PyPI 官网下载 | orderedset-1.2.tar.gz"表明这是一个在Python Package Index (PyPI)上发布的软件包,名为`orderedset-1.2`,并且是以`.tar.gz`格式提供的。PyPI是Python社区用于分发、发现和安装第三方...
北大POJ2533-Longest Ordered Subsequence【O(nlogn)】
Pku acm 第2533题 Longest Ordered Subsequence 代码,有详细的注释,动态规划
"Laravel开发-ordered-eloquent"这个项目则是针对Eloquent ORM的一个扩展,旨在实现自动排序查询结果的功能。 这个扩展名为Ordered Eloquent,其主要目标是让开发者在使用Eloquent查询时,能够更加方便地对结果进行...
M13OrderedDictionary, 带有有序对象和键的NSDictionary M13OrderedDictionaryM13OrderedDictionary是NSArray和NSDictionary之间的交叉。 它包含一个有序的对象和键列表。 所有这些都可以通过索引或者键访问。 这里...
标题“POJ2533-Longest Ordered Subsequence”是指北京大学在线判题系统POJ上的一道编程题目,其核心任务是寻找一个序列中最长的有序子序列。描述中的“解题报告+AC代码”表明这个压缩包包含了对这道问题的解答思路...
OrderedDictionary, 这里库提供OrderedDictionary和MutableOrderedDictionary子类 命令行目存储在NSDictionary中的对象的顺序未定义。 通常,可以以通过一组键/值对循环,并按照插入的顺序返回对象。 这个库提供了两...
OrderedSet 静态的,有序的唯一对象集合。 关于 简而言之, OrderedSet是Array和Set的混合体。 像Array一样,它的元素具有定义的顺序,但是它像Set一样在其成员上强制唯一性。 在以下情况下,可以使用OrderedSet...
在Java编程语言中,`OrderedList`是一种特殊的集合类,它不仅提供了集合的基本操作,如添加、删除和查找元素,还特别强调了元素的顺序。标题"OrderedList:OrderedList(与JDK1.7一起编译)"暗示了这个项目或者库是...
ordered-set是一个高性能的 ES6 Set 子类,它允许控制迭代顺序。 只需为 set 提供要use的排序函数,剩下的就交给它了。 const OrderedSet = require ( 'ordered-set' ) let orderedSet = new OrderedSet ( ) ...
** Meteor 有序字典(Ordered Dict)** 在前端开发领域,`meteor-ordered-dict` 是一个非常重要的工具,尤其对于使用 Meteor 框架的开发者来说。Meteor 是一个全栈 JavaScript 开发框架,它允许开发者用同一种语言...
OrderedSet(['a', 'b', 'r', 'c', 'd']) >>> 'r' in letters True 在OrderedSet中查找条目的索引,或通过其索引查找条目,效率很高。 为了帮助解决该用例, .add()方法返回添加项的索引,无论它是否已经在集合中。 ...
Subject: ORDERED Hint in Complex Searches Doc ID: 408049.1 Type: PROBLEM Modified Date : 08-JUL-2009 Status: PUBLISHED
"ordered-map"是一个库,它提供了一种特殊的哈希映射(HashMap)和哈希集(HashSet)实现,特点是它们能保留元素的插入顺序。这对于需要同时保持键值对排序和高效查找的场景非常有用。在C++标准库中,`std::map`和`...
Merge two lists of ordered numbers
《深入理解Django有序模型库django-ordered-model》 Django是Python中广泛使用的Web开发框架,它以其高效、简洁的语法和强大的功能而受到开发者们的喜爱。在众多的Django扩展库中,`django-ordered-model`是一个...
在偏序幺半群的上下文中,正锥通常用M+表示,它具有以下性质:对于M+中的任意元素a, b和c,如果a ≤ b + c,那么存在正元x和y,使得a = x + y且x ≤ b,y ≤ c。这与线性空间中的正锥定义类似,但扩展到了非交换结构...