aboutsummaryrefslogtreecommitdiff
path: root/srchr/src/layout.rs
diff options
context:
space:
mode:
Diffstat (limited to 'srchr/src/layout.rs')
-rw-r--r--srchr/src/layout.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/srchr/src/layout.rs b/srchr/src/layout.rs
index 8f8b03a..e6ac862 100644
--- a/srchr/src/layout.rs
+++ b/srchr/src/layout.rs
@@ -167,7 +167,31 @@ impl Layout {
}
let w_index_columns = weight_function(&pl.index_columns, corpus);
- let (left_ind, right_ind) = if balance >= 0.0 { (0, 1) } else { (1, 0) };
+ // Choose index order to minimise LSB (middle-index only) even though we
+ // don't directly optimise for this parameter
+ let mut lsbs = [0.0; 2];
+ for option in [0, 1] {
+ for left in [true, false] {
+ let mind = if left { 2 } else { 7 };
+ let side = if left { option } else { 1 - option };
+ let m1 = keys[mind + 10 * 0] as u8;
+ let m2 = keys[mind + 10 * 1] as u8;
+ let m3 = keys[mind + 10 * 2] as u8;
+ let i1 = w_index_columns[side].0[3];
+ let i2 = w_index_columns[side].0[4];
+ let i3 = w_index_columns[side].0[5];
+ lsbs[option] += corpus.get_bigram_perc(m1, i1)
+ + corpus.get_bigram_perc(m1, i2)
+ + corpus.get_bigram_perc(m1, i3)
+ + corpus.get_bigram_perc(m2, i1)
+ + corpus.get_bigram_perc(m2, i2)
+ + corpus.get_bigram_perc(m2, i3)
+ + corpus.get_bigram_perc(m3, i1)
+ + corpus.get_bigram_perc(m3, i2)
+ + corpus.get_bigram_perc(m3, i3);
+ }
+ }
+ let (left_ind, right_ind) = if lsbs[0] < lsbs[1] { (0, 1) } else { (1, 0) };
for j in 0..3 {
keys[3 + j * ROW_LENGTH] = w_index_columns[left_ind].0[j] as char;
keys[6 + j * ROW_LENGTH] = w_index_columns[right_ind].0[j] as char;