[73] | 1 | open Kosuzu
|
---|
| 2 |
|
---|
| 3 | module Rel = struct
|
---|
| 4 |
|
---|
| 5 | module Rel_set = Set.Make(String)
|
---|
| 6 | module Id_map = Map.Make(String)
|
---|
| 7 |
|
---|
| 8 | type t = { last_rel: string; ref_set: String_set.t; rep_set: String_set.t }
|
---|
| 9 | type map_t = t Id_map.t
|
---|
| 10 |
|
---|
| 11 | let empty = { last_rel = ""; ref_set = Rel_set.empty; rep_set = Rel_set.empty }
|
---|
| 12 | let empty_map = Id_map.empty
|
---|
| 13 |
|
---|
| 14 | let acc_ref date source target = Id_map.update target (function
|
---|
| 15 | | None -> Some { last_rel = date;
|
---|
| 16 | ref_set = Rel_set.singleton source;
|
---|
| 17 | rep_set = Rel_set.empty }
|
---|
| 18 | | Some rel -> Some { rel with
|
---|
| 19 | last_rel = if Date.compare date rel.last_rel > 0 then date else rel.last_rel;
|
---|
| 20 | ref_set = Rel_set.add source rel.ref_set })
|
---|
| 21 |
|
---|
| 22 | let acc_rep date source target = Id_map.update target (function
|
---|
| 23 | | None -> Some { last_rel = date;
|
---|
| 24 | rep_set = Rel_set.singleton source;
|
---|
| 25 | ref_set = Rel_set.empty }
|
---|
| 26 | | Some rel -> Some { rel with
|
---|
| 27 | last_rel = if Date.compare date rel.last_rel > 0 then date else rel.last_rel;
|
---|
| 28 | rep_set = Rel_set.add source rel.rep_set })
|
---|
| 29 |
|
---|
| 30 | let acc_txt rels (text, _paths) =
|
---|
| 31 | let acc_ref = acc_ref (Date.listing text.Text.date) text.Text.id in
|
---|
| 32 | let acc_rep = acc_rep (Date.listing text.Text.date) text.Text.id in
|
---|
| 33 | let rels = String_set.fold acc_ref (Text.set "references" text) rels in
|
---|
| 34 | let rels = String_set.fold acc_rep (Text.set "in-reply-to" text) rels in
|
---|
| 35 | rels
|
---|
| 36 |
|
---|
| 37 | let acc_pck rels peer =
|
---|
| 38 | let path = try List.hd peer.Peers.pack.Header_pack.info.locations with Failure _->"" in
|
---|
| 39 | try Header_pack.fold
|
---|
| 40 | (fun rels id t _title _authors _topics refs_ls reps_ls ->
|
---|
| 41 | let acc_ref = acc_ref (Date.of_secs @@ Int32.to_int t) (Filename.concat path id) in
|
---|
| 42 | let acc_rep = acc_rep (Date.of_secs @@ Int32.to_int t) (Filename.concat path id) in
|
---|
| 43 | let rels = String_set.fold acc_ref (String_set.of_list refs_ls) rels in
|
---|
| 44 | let rels = String_set.fold acc_rep (String_set.of_list reps_ls) rels in
|
---|
| 45 | rels)
|
---|
| 46 | rels peer.Peers.pack
|
---|
| 47 | with e -> prerr_endline "acc_pck"; raise e
|
---|
| 48 | end
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | type t = {
|
---|
| 52 | id: string;
|
---|
| 53 | dir: string;
|
---|
| 54 | kv: string Store.KV.t;
|
---|
| 55 | topic_roots: string list;
|
---|
| 56 | topics: (String_set.t * String_set.t) Topic_set.Map.t;
|
---|
| 57 | relations: Rel.map_t;
|
---|
| 58 | texts: Text.t list
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | type fn_t = {
|
---|
| 62 | ext: string;
|
---|
| 63 | page: (t -> Kosuzu.Text.t -> string) option;
|
---|
| 64 | indices: (t -> unit) option;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | let empty () = {
|
---|
| 68 | id = ""; dir = "";
|
---|
| 69 | kv = Store.KV.empty;
|
---|
| 70 | topic_roots = [];
|
---|
| 71 | topics = Topic_set.Map.empty;
|
---|
| 72 | relations = Rel.Id_map.empty;
|
---|
| 73 | texts = []
|
---|
| 74 | }
|
---|