[Python-checkins] python/nondist/sandbox/spambayes rebal.py,1.1,1.2

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Sat, 31 Aug 2002 12:09:10 -0700


Update of /cvsroot/python/python/nondist/sandbox/spambayes
In directory usw-pr-cvs1:/tmp/cvs-serv3319

Modified Files:
	rebal.py 
Log Message:
Aha!  Staring at the checkin msg revealed a logic bug that explains why
my ham directories sometimes remained unbalanced after running this --
if the randomly selected reservoir msg turned out to be spam, it wasn't
pushing the too-small directory on the stack again.


Index: rebal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/spambayes/rebal.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** rebal.py	31 Aug 2002 18:52:38 -0000	1.1
--- rebal.py	31 Aug 2002 19:09:08 -0000	1.2
***************
*** 27,30 ****
--- 27,33 ----
  while stuff:
      dir, fs = stuff.pop()
+     if len(fs) == NPERDIR:
+         continue
+ 
      if len(fs) > NPERDIR:
          f = random.choice(fs)
***************
*** 32,36 ****
          print "deleting", f, "from", dir
          os.unlink(dir + "/" + f)
!         stuff.append((dir, fs))
      elif len(fs) < NPERDIR:
          print "need a new one for", dir
--- 35,39 ----
          print "deleting", f, "from", dir
          os.unlink(dir + "/" + f)
! 
      elif len(fs) < NPERDIR:
          print "need a new one for", dir
***************
*** 42,45 ****
--- 45,49 ----
          guts = fp.read()
          fp.close()
+         os.unlink(RESDIR + "/" + f)
  
          print guts
***************
*** 49,53 ****
              fp.write(guts)
              fp.close()
-             os.unlink(RESDIR + "/" + f)
              fs.append(f)
!             stuff.append((dir, fs))
--- 53,57 ----
              fp.write(guts)
              fp.close()
              fs.append(f)
! 
!     stuff.append((dir, fs))