let compare_by_depth s1 s2 =
let v1 = dim s1 in
let v2 = dim s2 in
let c = Pervasives.compare v1 v2 in
if c <> 0 then c else
let c1 = size s1 in
let c2 = size s2 in
let c = Pervasives.compare c1 c2 in
if c <> 0 then c else
let c = compare_kind s1 s2 in
if c <> 0 then c else
let c = Pervasives.compare s2.depth s1.depth in
if c <> 0 then c else
Pervasives.compare (abs s1.tag) (abs s2.tag)