/**
* use as java.util.hashset
*/
function testhashset(){
alert("hashset test begin:");
try{
}
catch(e){
alert(e);
}
alert("hashset test end");
}
function hashset(){
private:
this.map=new hashmap();
this.zero=new integer(0);
function hashiterator(it){
this.it=it;
this.hasnext=hasnext;
function hasnext() {
return this.it.hasnext();
}
this.next=next;
function next() {
return this.it.next().getkey();
}
}
public:
this.size=size;
function size(){
return this.map.size();
}
this.isempty=isempty;
function isempty() {
return this.map.isempty();
}
this.contains=contains;
function contains(o) {
return this.map.containskey(o);
}
this.add=add;
function add(o) {
return this.map.put(o,this.zero)==null;
}
this.addall=addall;
function addall(set){
var mod=false;
for(var it=set.iterator();it.hasnext();){
if(this.add(it.next())) mod=true;
}
return mod;
}
this.remove=remove;
function remove(o) {
return this.map.remove(o).equals(this.zero);
}
this.clear=clear;
function clear() {
this.map.clear();
}
this.iterator=iterator;
function iterator(){
return new hashiterator(this.map.iterator());
}
this.equals=equals;
function equals(o) {
if (o.size() != this.size())
return false;
for(var it=this.iterator();it.hasnext();){
if(!o.contains(it.next())) return false;
}
return true;
}
this.hashcode=hashcode;
function hashcode() {
var h=0;
for(var it=this.iterator();it.hasnext();){
h+=it.next().hashcode();
}
return h;
}
this.toarray=toarray;
function toarray(){
var arr=new array();
var i=0;
for(var it=this.iterator();it.hasnext();){
arr[i++]=it.next();
}
return arr;
}
}