/*
 *  NekoML Standard Library
 *  Copyright (c)2005 Motion-Twin
 *
 *  This library 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.1 of the License, or (at your option) any later version.
 *
 *  This library 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 or the LICENSE file for more details.
 */

type ('a,'b) t;

function hash(x:'a) : int {
	neko("$hkey(x)")
}

function create() : ('a,'b) t {
	neko("$hnew(0)")
}

function length(h : ('a,'b) t) : int {
	neko("$hcount(h)")
}

function find(h : ('a,'b) t,k : 'a) : 'b {
	var v = neko("$hget(h,k,@Core.@compare)");
	if neko("v == null") then throw Not_found;
	v
}

function exists(h : ('a,'b) t,k : 'a) : bool {
	neko("$hmem(h,k,@Core.@compare)");
}

function add(h : ('a,'b) t, k : 'a, v : 'b) : void {
	neko("$hadd(h,k,v)");
}

function remove(h : ('a,'b) t,k : 'a) : void {
	neko("$hremove(h,k,@Core.@compare)");
}

function replace(h : ('a,'b) t,k : 'a,v : 'b) : void {
	neko("$hset(h,k,v,@Core.@compare)");
}

function iter(f : 'a -> 'b -> void,h : ('a,'b) t) : void {
	neko("$hiter(h,f)");
}
