From dbd96016ed19df39c64cb5ce0ac758fb40087c42 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 27 Apr 2015 22:58:10 -0400 Subject: [PATCH] lib/bucketed_game: revamp constructor of `Buckets` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/bucketed_game.nit | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/bucketed_game.nit b/lib/bucketed_game.nit index ae0d792..eba5d69 100644 --- a/lib/bucketed_game.nit +++ b/lib/bucketed_game.nit @@ -48,20 +48,16 @@ class Buckets[G: Game] # Bucket type used in this implementation. type BUCKET: HashSet[Bucketable[G]] - private var buckets: Array[BUCKET] is noinit - private var next_bucket: nullable BUCKET = null private var current_bucket_key: Int = -1 - init - do - var n_buckets = 100 - buckets = new Array[BUCKET].with_capacity(n_buckets) + # Number of `buckets`, default at 100 + # + # Must be set prior to using any other methods of this class. + var n_buckets = 100 - for b in [0 .. n_buckets [do - buckets[b] = new HashSet[Bucketable[G]] - end - end + private var buckets: Array[BUCKET] = + [for b in n_buckets.times do new HashSet[Bucketable[G]]] is lazy # Add the Bucketable event `e` at `at_tick`. fun add_at(e: Bucketable[G], at_tick: Int) -- 1.7.9.5