gleam-lang/gleam

Optimise decision tree for bit arrays

Geschlossen

#4.524 geöffnet am 29.04.2025

 (9 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)Rust (960 Forks)batch import
help wanted

Repository-Metriken

Stars
 (21.417 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 10T 19h) (69 gemergte PRs in 30 T)

Beschreibung

Right now when generating code for bit arrays we might end up doing something like this:

if (size > n) {
  if (size === n + 10) {
    // ...
  } else {
    // body_1
  }
} else {
  // body_1
}

If all else branches have the same body it would be really nice to make the tree shorter and skip the first check entirely:

if (size === n + 10) {
  // ...
} else {
  // body_1
}

This might be quite challenging and could require reading more on how to reduce the tree size: this could be a very good resource for that https://user.it.uu.se/~kostis/Papers/JFP_06.pdf

Contributor Guide