Skip to content

Commit

Permalink
return complete tops of sorted arrays sharing the same top count in s…
Browse files Browse the repository at this point in the history
…uffice, abbreviate with take max in report
  • Loading branch information
alexy committed Jan 7, 2009
1 parent 1d522ee commit d1801d9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ all: sent

utils.cmo: utils.ml
ocamlfind ocamlc $(DEBUG) -package pcre -c $^ -o $@

utils.cmx: utils.ml
ocamlfind ocamlopt $(DEBUG) -package pcre -c $^ -o $@

sent: seq.cmo utils.cmo common.cmo baseclient.cmo $(LMCLASS_A) generate.ml
ocamlfind ocamlc $(DEBUG) -package pcre -linkpkg $(LMCLIENT_A) $(CC_LIBS) $^ -o $@
Expand All @@ -63,13 +66,13 @@ $(LMCLASS_A): $(LMCLASS_A:.cmo=.ml)
%.cmx: %.ml
ocamlfind ocamlopt -c $< -o $@

treeru: seq.cmo treeru.ml
treeru: seq.cmo utils.cmo treeru.ml
echo suffix objects: $(SUFFIX_CMOS)
ocamlfind ocamlc -package str -linkpkg -I $(SUFFIX_DIR) $(SUFFIX_CMOS) $^ -o $@
ocamlfind ocamlc -package str,pcre -linkpkg -I $(SUFFIX_DIR) $(SUFFIX_CMOS) $^ -o $@

treeru.opt: seq.cmx treeru.ml
treeru.opt: seq.cmx utils.cmx treeru.ml
echo suffix objects: $(SUFFIX_CMXS)
ocamlfind ocamlopt -package str -linkpkg -I $(SUFFIX_DIR) $(SUFFIX_CMXS) $^ -o $@
ocamlfind ocamlopt -package str,pcre -linkpkg -I $(SUFFIX_DIR) $(SUFFIX_CMXS) $^ -o $@

unis: seq.cmo unis.ml
ocamlfind ocamlc -package unix,str -linkpkg $^ -o $@
Expand Down
14 changes: 13 additions & 1 deletion intree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,16 @@ let suffice t s =
let a2 = sort_hash h2 in
if Array.length a1 > 0 then Some a1.(0)
else if Array.length a2 > 0 then Some a2.(0)
else None
else None

(* we assume the pairs array is sorted by the second element! *)
let top_ids ap =
let len = Array.length ap in
if len = 0 then (0,[])
else
let c = snd a.(0) in
let rec go i acc =
if i >= len || snd a.(i) <> c then acc
else go (i+1) ((fst a.(i))::acc)
in
(c, go 0 [])
37 changes: 27 additions & 10 deletions treeru.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,24 @@ let incr_hash h k =
Hashtbl.find h k else 0 in
Hashtbl.replace h k (v+1)

type clist = int * int list
type hitmax =
| Both of ((int * int) * (int * int))
| Hit of (int * int) | Max of (int * int) | None
| Both of (clist * clist)
| Hit of clist | Max of clist | Miss

let nonempty a = Array.length a > 0

let top_ids a =
let len = Array.length a in
if len = 0 then (0,[])
else
let c = snd a.(0) in
let rec go i acc =
if i >= len || snd a.(i) <> c then acc
else go (i+1) ((fst a.(i))::acc)
in
(c, go 0 [])

let suffice t s =
let h1 = Hashtbl.create 1000 in
let h2 = Hashtbl.create 1000 in
Expand All @@ -104,20 +116,25 @@ let suffice t s =
let a1 = sort_hash h1 in
let a2 = sort_hash h2 in
if nonempty a1 && nonempty a2 then
Both (a1.(0),a2.(0))
Both (top_ids a1, top_ids a2)
else if nonempty a1 then
Hit a1.(0)
Hit (top_ids a1)
else if nonempty a2 then
Max a2.(0)
else None
Max (top_ids a2)
else Miss

let show_ids ?(max=3) li =
let l = Utils.take max li in
let l's = List.map string_of_int l in
String.concat "|" l's

let do_sample t sample =
let s = Array.of_list sample in begin
match suffice t s with
| Both ((s1,_),(s2,_)) -> printf " %d,%d" s1 s2
| Hit (s,_) -> printf " %d!" s
| Max (s,_) -> printf " %d?" s
| None -> printf " *"
| Both ((_,s1),(_,s2)) -> printf " %s,%s" (show_ids s1) (show_ids s2)
| Hit (_,s) -> printf " %s!" (show_ids s)
| Max (_,s) -> printf " %s?" (show_ids s)
| Miss -> printf " *"
end
(* ; print_endline "" *)

Expand Down

0 comments on commit d1801d9

Please sign in to comment.