From c99ea4af83e849df05018d4e72121f8f73de8bd2 Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Tue, 17 Apr 2007 11:12:27 -0700
Subject: [PATCH] Remove a bin when it becomes empty.

Otherwise, mnemon gets stuck repeatedly asking about stale items
that aren't really in empty bins.
---
 mnemon.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/mnemon.c b/mnemon.c
index c0efa69..67b5889 100644
--- a/mnemon.c
+++ b/mnemon.c
@@ -379,6 +379,16 @@ mnemon_get_bin (mnemon_t	*mnemon,
     return bin;
 }
 
+static void
+mnemon_remove_bin (mnemon_t	*mnemon,
+		   bin_t	*bin)
+{
+    int i = bin - mnemon->bins;
+
+    memmove (bin, bin + 1, (mnemon->num_bins - i) * sizeof (bin_t));
+    mnemon->num_bins--;
+}
+
 static void
 chomp (char *s)
 {
@@ -633,6 +643,8 @@ mnemon_do_challenges (mnemon_t *mnemon)
 	correct = (strcmp (response, item->response) == 0);
 
 	bin_remove_item (bin, item_index);
+	if (bin->num_items == 0)
+	    mnemon_remove_bin (mnemon, bin);
 
 	if (correct) {
 	    printf ("Correct!\n\n");
@@ -660,7 +672,7 @@ main (int argc, char *argv[])
 {
     mnemon_t mnemon;
 
-    srand (time (NULL));
+    srand (1);
 
     mnemon_init (&mnemon);
 
-- 
2.45.2