Topic: 关于TreeSet:怎么从已知相近点开始查找? |
Print this page |
1.关于TreeSet:怎么从已知相近点开始查找? | Copy to clipboard |
Posted by: zy_ball Posted on: 2004-09-02 00:36 class MyClass implements Comparable { long ID; public int compareTo(java.lang.Object rhs) { MyClass mc = (MyClass)rhs; if(ID < mc.ID) return -1; else if(ID > mc.ID) return 1; else return 0; } } Collection t = new TreeSet(); t中包含的都是MyClass对象,其中有一个ID为5, 那么我怎么才能最快的访问到ID为5的这个包含在t中的对象呢? 迭代肯定很快,因为是Tree嘛,但是每次迭代都要从头,多费事啊,没有更好的办法了吗? 谢谢! |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |