First very rough commit, but tests suggest the new Spark affinity computation gives the same results as a legacy implementation. This is good news.