@bruvik like most problems in computer science, the solutions can be found in prior art.