This file is indexed.

/usr/share/doc/ats-lang-anairiats-examples/examples/TEST/libats_hashtable_chain.dats is in ats-lang-anairiats-examples 0.2.5-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(*
//
// Author: Hongwei Xi (March, 2010)
//
*)

(* ****** ****** *)

staload RAND = "libc/SATS/random.sats"

(* ****** ****** *)

staload _(*anon*) = "prelude/DATS/reference.dats"

(* ****** ****** *)

staload H = "libats/SATS/hashtable_chain.sats"
staload _(*anon*) = "libats/DATS/hashtable_chain.dats"

stadef HASHTBLptr = $H.HASHTBLptr

(* ****** ****** *)

// dynload "hashtable_chain.dats" // not needed as [ATS_DYNLOADFLAG = 0]

(* ****** ****** *)

(*
** the efficiency gained from inlining the comparison
** function seems to be less than 5% (more like a 3%)
*)

// (*
//
// Robert Jenkin's 32-bit function:
//
%{^
ats_int_type
__jenkin32 (ats_int_type x) {
  uint32_t a = x ;
  a = (a+0x7ed55d16) + (a<<12);
  a = (a^0xc761c23c) ^ (a>>19);
  a = (a+0x165667b1) + (a<<5);
  a = (a+0xd3a2646c) ^ (a<<9);
  a = (a+0xfd7046c5) + (a<<3);
  a = (a^0xb55a4f09) ^ (a>>16);
  return a;
} // end of [__jenkin]
%} // end of [%{^]
extern fun __jenkin32 (x: int):<> int = "__jenkin32"
implement
$H.hash_key<int> (x, _) = let
  val h = __jenkin32 (x) in ulint_of_int (h)
end // end of [hash_key]

implement $H.equal_key_key<int> (x1, x2, _) = (x1 = x2)
// *)

implement main (argc, argv) = let
  val () = gc_chunk_count_limit_max_set (~1) // infinite
  var n: int = 0
  val () = begin
    if argc >= 2 then n := int_of_string (argv.[1])
  end
  val [n:int] n = int1_of n
  val () = assert_errmsg (n > 0, #LOCATION)
(*
  val () = $RAND.srand48_with_time ()
*)
  typedef key = int and itm = string
  fn hash (x: key):<cloref> ulint = ulint_of_int (x)
  fn eq (x1: key, x2: key):<cloref> bool = (x1 = x2)

  val [l:addr] ptbl = $H.hashtbl_make {int,string} (hash, eq)
  var i: int; val () = for (i := 0; i < n; i := i+1) let
    val key = i
    // val key = $RAND.randint n
    val itm = tostring key // val itm = sprintf ("%i", @(key))
    // val () = printf ("key = %i and itm = %s\n", @(key, itm))
  in
    $H.hashtbl_insert<key,itm> (ptbl, key, itm)
  end // end [for]
  val size = $H.hashtbl_size (ptbl)
  val total = $H.hashtbl_total (ptbl)
  val () = begin
    print "size = "; print size; print_newline ();
    print "total = "; print total; print_newline ();
  end // end of [val]
//
  fn find {l:agz} (
      ptbl: !HASHTBLptr (key, itm, l), k0: key, res: &itm?
    ) : void = () where {
    val () = printf ("%i\t->\t", @(k0))
    val ans = $H.hashtbl_search (ptbl, k0, res)
    val () = if ans then let
      prval () = opt_unsome {itm} (res) in
      print "Some("; print res; print ")"
    end else let
      prval () = opt_unnone {itm} (res) in
      print "None()"
    end // end of [if]
    val () = print_newline ()
  } // end of [find]
//
  var res: itm?
//
  val k0 = 0
  val () = find (ptbl, k0, res)
  val k1 = 1
  val () = find (ptbl, k1, res)
  val k10 = 10
  val () = find (ptbl, k10, res)
  val k100 = 100
  val () = find (ptbl, k100, res)
  val k1000 = 1000
  val () = find (ptbl, k1000, res)
  val k10000 = 10000
  val () = find (ptbl, k10000, res)
//
  #define p2s string_of_strptr
  var !p_f = @lam
    (pf: !unit_v | k: key, i: &itm): void =<clo> i := p2s (sprintf ("%i", @(k+k+1)))
  // end of [var]
  prval pf = unit_v ()
  val () = $H.hashtbl_foreach_vclo<key,itm> {unit_v} (pf | ptbl, !p_f)
  prval unit_v () = pf
//
  val () = find (ptbl, k10000, res)
//
  var i: int; val () = for (i := 0; i < n; i := i+1) let
    val key = i
    // val key = $RAND.randint n
    val ans = $H.hashtbl_remove<key,itm> (ptbl, key, res)
    prval () = opt_clear (res)
  in
    // nothing
  end // end [for]
//
  val total = $H.hashtbl_total (ptbl)
  val () = (print "total(aft) = "; print total; print_newline ())
  val notfreed = $H.hashtbl_free_vt (ptbl)
  val () = assert_errmsg (notfreed = false, #LOCATION)
  prval () = opt_unnone (ptbl)
in
  // empty
end // end of [main]

(* ****** ****** *)

(* end of [libats_hashtable_chain.dats] *)