]> git.pond.sub.org Git - empserver/commit
news: Rewrite code for "The Bottom Line"
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 27 Jun 2016 19:05:10 +0000 (21:05 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 6 Aug 2017 18:09:17 +0000 (20:09 +0200)
commit68e595af8afcb20f06a5ebd63f201e2e4a1c96df
tree749d1503f92df327ad1af1e51b78be84f6d7bfc5
parentd63b8aa5f077ed0139a9a4180f4a7d35077a088f
news: Rewrite code for "The Bottom Line"

This is one of the lamest ways to sort I've seen in my career: find
the maximum, then for each value from the maximum down, search for
that value.  O(max * MAXNOC^2).  Dates back to Empire 2.

The one advantage this contraption has is it "sorts" in place.  But
memory's cheap.  Fill an array with the data to sort, and sort it with
qsort().  To avoid overtaxing the stack in the (unlikely!) worst case
of everybody taking sectors from everybody, allocate it dynamically.

Also flip sectors_taken[] from short to unsigned short.  Aside: in
theory, the count can overflow, but sector deltas exceeding 65535
don't occur in practice, and if news misreported them, we'd live.  Not
worth complicating the code.

Signed-off-by: Markus Armbruster <armbru@pond.sub.org>
src/lib/commands/news.c