Debian Codegraph @

src/core/Hashtbl.nml

raw
1 /*
2 * Copyright (C)2005-2022 Haxe Foundation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 */
22
23 type ('a,'b) t;
24
25 function hash(x:'a) : int {
26 neko("$hkey(x)")
27 }
28
29 function create() : ('a,'b) t {
30 neko("$hnew(0)")
31 }
32
33 function length(h : ('a,'b) t) : int {
34 neko("$hcount(h)")
35 }
36
37 function find(h : ('a,'b) t,k : 'a) : 'b {
38 var v = neko("$hget(h,k,@Core.@compare)");
39 if neko("v == null") then throw Not_found;
40 v
41 }
42
43 function exists(h : ('a,'b) t,k : 'a) : bool {
44 neko("$hmem(h,k,@Core.@compare)");
45 }
46
47 function add(h : ('a,'b) t, k : 'a, v : 'b) : void {
48 neko("$hadd(h,k,v)");
49 }
50
51 function remove(h : ('a,'b) t,k : 'a) : void {
52 neko("$hremove(h,k,@Core.@compare)");
53 }
54
55 function replace(h : ('a,'b) t,k : 'a,v : 'b) : void {
56 neko("$hset(h,k,v,@Core.@compare)");
57 }
58
59 function iter(f : 'a -> 'b -> void,h : ('a,'b) t) : void {
60 neko("$hiter(h,f)");
61 }