• 0

    posted a message on Changes to the LibBabble Libraries - Translators Read!
    Would it be possible to add the full names of zone chat channels ("General - %s", "Trade - City" and "LocalDefense - %s")? I have an add-on that needs "Trade - City" for a unit test, and it's not in GlobalStrings.lua for some reason.
    Posted in: Libraries
  • 0

    posted a message on Optimize a hash table with a size limit
    I have several CPU-heavy functions whose output I want to cache, but I need to limit the number of cache entries so the table won't grow large enough to cause hard page faults. What I've been doing so far is:

    function LFMonitor:cacheLookup(table, item, fallback, disableCaching)
      assert(item, "LFMonitor:cacheLookup called with nil item")
      if disableCaching then
        return fallback(item)
      if not table.score then
        table.score = {}
      if table.score[item] then
    	return table.score[item]
    	local score = fallback(item)
    	if table.count >= table.max then
    		table.score[next(table.score)] = nil
    		table.count = table.count + 1
    	table.score[item] = score
    	return score

    However, next() sometimes returns the newest index in the table, and it'd be better to remove the oldest index (since it's less likely to be used again soon). I'm also not sure whether adding and removing entries one-by-one is optimal.
    Posted in: Need Help?
  • To post a comment, please or register a new account.