(FILECREATED " 8-Dec-85 17:40:34" {QV}<NOTECARDS>1.3K>RHTPATCH014.;2 5883   

      changes to:  (VARS RHTPATCH014COMS)
		   (FNS NC.PutHashArray)

      previous date: " 7-Dec-85 21:01:50" {QV}<NOTECARDS>1.3K>RHTPATCH014.;1)


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT RHTPATCH014COMS)

(RPAQQ RHTPATCH014COMS ((* * These functions redefined from NCDATABASE)
			  (FNS NC.GetHashArray NC.GetNewCard NC.PutHashArray)))
(* * These functions redefined from NCDATABASE)

(DEFINEQ

(NC.GetHashArray
  (LAMBDA (NoteFile QuietFlg OperationMsg)                   (* rht: " 7-Dec-85 19:51")

          (* * Fill NoteFile's hash array by reading from the index on NoteFile.)



          (* * rht 12/6/85: Fixed to build free list of IndexNum's.)



          (* * rht 12/7/85: Minor addition of print statement in front of loop.)


    (OR OperationMsg (SETQ OperationMsg ""))
    (WITH.MONITOR (NC.FetchMonitor NoteFile)
		  (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			(CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
			IndexNumsFreeList)
		       (OR QuietFlg (NC.PrintMsg NIL T OperationMsg 
						     "Reading in hash array: item number "
						     1 " out of " CardTotal "." (CHARACTER 13)))
		       (SETFILEPTR Stream (CONSTANT (fetch (NoteFileVersion NoteFileHeaderSize)
							   of (NC.FetchCurrentVersionObject))))
		       (NC.PrintMsg NIL T OperationMsg "Reading in hash array: item number " 1 
				      " out of "
				      CardTotal "." (CHARACTER 13))
		       (for IndexNum from 1 to CardTotal bind Card eachtime (BLOCK)
			  do (OR QuietFlg (AND (ZEROP (REMAINDER IndexNum 100))
						     (NC.PrintMsg NIL T OperationMsg 
							    "Reading in hash array: item number "
								    IndexNum " out of " CardTotal "."
								    (CHARACTER 13))))
			       (SETQ Card (NC.ReadIndexEntry NoteFile))
			       (if (EQ (fetch (Card Status) of Card)
					   (QUOTE FREE))
				   then (push IndexNumsFreeList IndexNum)))
		       (replace (NoteFile IndexNumsFreeList) of NoteFile with IndexNumsFreeList)
		    ))))

(NC.GetNewCard
  (LAMBDA (NoteFile DontUpdateFlg OptionalUID)               (* rht: " 7-Dec-85 20:23")

          (* * rht 1/9/85: Keep track of the total number of cards in NC.UncachingNotCompleted.)



          (* * rht 1/31/85: Increases array size if needed. Also now stores highest ID number in a global var and only writes
	  to the file at checkpoint time.)



          (* * rht 2/1/85: Now warn user if within 90% of index full. Also if index array is full, then increase its size.)



          (* * fgh 10/15/85 increase cache arry size when necessary)



          (* * rht 11/12/85: Updated to handle NoteFile format.)



          (* * rht 12/6/85: Fixed to reuse free index num if any. Find these on IndexNumsFreeList.)



          (* * rht 12/7/85: Added OptionalUID argument, so can build new card but assign it a given UID.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  (NextIndexNum (fetch (NoteFile NextIndexNum) of NoteFile))
	  (IndexSize (fetch (NoteFile HashArraySize) of NoteFile))
	  (IndexNumsFreeList (fetch (NoteFile IndexNumsFreeList) of NoteFile))
	  IndexNum Card PercentUsed)
         (if IndexNumsFreeList
	     then (SETQ IndexNum (pop IndexNumsFreeList))
		    (replace (NoteFile IndexNumsFreeList) of NoteFile with IndexNumsFreeList)
	   else (SETQ IndexNum NextIndexNum)
		  (replace (NoteFile NextIndexNum) of NoteFile with (ADD1 NextIndexNum)))
         (if (GREATERP (SETQ PercentUsed (FIX (TIMES 100 (QUOTIENT (FLOAT NextIndexNum)
									       (FLOAT IndexSize)))))
			   90)
	     then (NC.PrintMsg NIL T "Index for notefile: " (FULLNAME Stream)
				   " is " PercentUsed "%% full." (CHARACTER 13)
				   "Please close notefile soon and compact."))
         (if (EQ NextIndexNum IndexSize)
	     then (NC.ReportError "NC.GetNewCard" "Index full."))
         (SETQ Card (create Card
				UID ←(if (type? UID OptionalUID)
					 then OptionalUID
				       else (NC.MakeUID))
				NoteFile ← NoteFile
				IndexLoc ←(NC.NoteFileLocFromIndexNum IndexNum)
				IndexDirtyFlg ← T))
         (NC.InstallCardInNoteFile Card NoteFile)
     Card)))

(NC.PutHashArray
  (LAMBDA (NoteFile QuietFlg OperationMsg AllActiveCardsFlg)
                                                             (* rht: " 8-Dec-85 17:39")

          (* * Write down the hash array's contents to the notefile.)



          (* * kirk 27Nov85 Added AllActiveCardsFlg for use by the compactor.)


    (LET ((CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
	  (Num 0))
         (OR QuietFlg (NC.PrintMsg NIL T OperationMsg (CHARACTER 13)
				       "Processing item number " 1 " out of " CardTotal "."
				       (CHARACTER 13)))
         (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
			    (SETQ Num (ADD1 Num))
			    (OR QuietFlg (AND (ZEROP (IREMAINDER Num 100))
						  (NC.PrintMsg NIL T OperationMsg 
								 "Processing item number "
								 Num " out of " CardTotal "."
								 (CHARACTER 13))))
			    (AND (if AllActiveCardsFlg
				       then (EQ (QUOTE ACTIVE)
						    (fetch (Card Status) of Card))
				     else (fetch (Card IndexDirtyFlg) of Card))
				   (NC.PutIndexEntry Card))))))))
)
(PUTPROPS RHTPATCH014 COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (524 5801 (NC.GetHashArray 534 . 2298) (NC.GetNewCard 2300 . 4623) (NC.PutHashArray 4625
 . 5799)))))
STOP