Commit e9c57cd6 authored by MARCHE Claude's avatar MARCHE Claude
Browse files

lcp: syntax OK until tests

parent 8619672a
......@@ -76,50 +76,40 @@ that it does so correctly.
module SuffixArray
use import int.Int
use import array.Array
type suffixArray = {
a : map int int;
suffixes : map int int;
n : int;
values : array int;
suffixes : array int;
}
let create (a:map int int) (length:int) : suffixArray =
let s = Array.make 0 length in
for i = 0 to length-1 do s[i] <- i done;
sort(s);
{ a = a;
n = length;
suffixes = s.elts;
}
let select (s:suffixArray) (i:int) : int = s.suffixes[i]
let select (s:suffixArray) (int i) : int = s.suffixes[i]
use import ref.Refint
let private_lcp (s:suffixArray) (x y:int) : int =
let n = s.n in
let lcp (a:array int) (x y:int) : int =
let n = a.length in
let l = ref 0 in
while x + !l < n && y + !l < n && s.a[x + !l] = a[y + !l] do
while x + !l < n && y + !l < n && a[x + !l] = a[y + !l] do
incr l
done;
!l
let lcp (s:suffixArray) (i:int) : int =
private_lcp s.suffixes[i] s.suffixes[i-1]
let compare (s:suffixArray) (x y:int) : int =
let compare (a:array int) (x y:int) : int =
if x = y then 0 else
let l = ref 0 in
while x + !l < n && y + !l < n && s.a[x + !l] = s.a[y + !l] do
incr l
done;
if x + !l = n then -1 else
if y + !l = n then 1 else
if s.a[x + !l] < s.a[y + !l] then -1 else
if s.a[x + !l] > s.a[y + !l] then 1 else
let n = a.length in
let l = lcp a x y in
if x + l = n then -1 else
if y + l = n then 1 else
if a[x + l] < a[y + l] then -1 else
if a[x + l] > a[y + l] then 1 else
absurd
let sort (s:suffixArray) (data : array int) =
for i = 0 to data.length do
let sort (a:array int) (data : array int) =
for i = 0 to data.length - 1 do
let j = ref i in
while j > 0 && compare s data[!j-1] data[!j] > 0 do
while !j > 0 && compare a data[!j-1] data[!j] > 0 do
let b = !j - 1 in
let t = data[!j] in
data[!j] <- data[b];
......@@ -128,6 +118,12 @@ let sort (s:suffixArray) (data : array int) =
done
done
let create (a:array int) : suffixArray =
let n = a.length in
let suf = Array.make 0 n in
for i = 0 to n-1 do suf[i] <- i done;
sort a suf;
{ values = a; suffixes = suf }
let test1 () =
int[] arr = {1,2,2,5};
......@@ -151,6 +147,10 @@ end
module LRS
let lcp (s:suffixArray) (i:int) : int =
SuffixArray.lcp s s.suffixes[i] s.suffixes[i-1]
private static int solStart = 0;
private static int solLength = 0;
private static int[] a;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment