(FILECREATED " 4-Nov-85 11:03:50" {MCS:MCS:STANFORD}<LANE>HASHBUFFER.LSP;6        

      previous date: "25-Oct-85 08:30:07" 
{MCS:MCS:STANFORD}<LANE>HASHBUFFER.LSP;5)


(PRETTYCOMPRINT HASHBUFFERCOMS)

(RPAQQ HASHBUFFERCOMS ((FNS CREATEHASHBUFFER OPENHASHBUFFER CLOSEHASHBUFFER 
			    GETHASHBUFFER PUTHASHBUFFER)
		       (INITVARS (EMPTYHASHENTRYMARKER '**EMPTYHASHENTRY**))
		       (GLOBALVARS EMPTYHASHENTRYMARKER)
		       (FNS HASHARRAY.TO.HASHFILE HASHFILE.TO.HASHARRAY)
		       (DECLARE: DONTCOPY (RECORDS HASHBUFFER))))
(DEFINEQ

(CREATEHASHBUFFER
  [LAMBDA (FILE VALUETYPE ITEMLENGTH #ENTRIES)
                                              (* cdl "24-Oct-85 08:25")
    (DECLARE (GLOBALVARS HASHFILEDEFAULTSIZE))
    (PROG [(HASHBUFFER (create HASHBUFFER
			       HASHFILE ←(CREATEHASHFILE FILE VALUETYPE 
							 ITEMLENGTH #ENTRIES)
			       HASHARRAY ←(HASHARRAY (OR #ENTRIES 
						      HASHFILEDEFAULTSIZE]
          (replace (HASHBUFFER ACCESS) of HASHBUFFER
	     with (GETFILEINFO (with HashFile (with HASHBUFFER HASHBUFFER 
						    HASHFILE)
				     Stream)
			       'ACCESS))
          (RETURN HASHBUFFER])

(OPENHASHBUFFER
  [LAMBDA (FILE ACCESS #ENTRIES)              (* cdl " 4-Nov-85 11:03")
    (PROG [(HASHBUFFER (create HASHBUFFER
			       HASHFILE ←(OPENHASHFILE FILE ACCESS]
          [replace (HASHBUFFER HASHARRAY) of HASHBUFFER
	     with (HASHARRAY (OR #ENTRIES (with HashFile
						(with HASHBUFFER HASHBUFFER 
						      HASHFILE)
						#Entries]
          (replace (HASHBUFFER ACCESS) of HASHBUFFER
	     with (GETFILEINFO (with HashFile (with HASHBUFFER HASHBUFFER 
						    HASHFILE)
				     Stream)
			       'ACCESS))
          (RETURN HASHBUFFER])

(CLOSEHASHBUFFER
  [LAMBDA (HASHBUFFER FILEONLY?)              (* cdl "24-Oct-85 08:20")
    (with HASHBUFFER HASHBUFFER (CLOSEHASHFILE HASHFILE)
	  (if (NOT FILEONLY?)
	      then (SETQ HASHARRAY NIL))
	  (HASHFILEPROP HASHFILE 'NAME])

(GETHASHBUFFER
  [LAMBDA (KEY HASHBUFFER)                    (* cdl "24-Oct-85 08:37")
    (PROG (VALUE)
          (with HASHBUFFER HASHBUFFER (if (EQ EMPTYHASHENTRYMARKER
					      (SETQ VALUE (GETHASH KEY 
								HASHARRAY)))
					  then (RETURN)
					elseif VALUE
					  then (RETURN VALUE)
					elseif (SETQ VALUE (GETHASHFILE
						   KEY HASHFILE))
					  then (PUTHASH KEY VALUE HASHARRAY)
					       (RETURN VALUE)
					else (PUTHASH KEY 
						     EMPTYHASHENTRYMARKER 
						      HASHARRAY])

(PUTHASHBUFFER
  [LAMBDA (KEY VALUE HASHBUFFER)              (* cdl "24-Oct-85 08:26")
    (with HASHBUFFER HASHBUFFER (if (NEQ ACCESS 'INPUT)
				    then (PUTHASHFILE KEY VALUE HASHFILE))
	  (PUTHASH KEY VALUE HASHARRAY])
)

(RPAQ? EMPTYHASHENTRYMARKER '**EMPTYHASHENTRY**)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS EMPTYHASHENTRYMARKER)
)
(DEFINEQ

(HASHARRAY.TO.HASHFILE
  [LAMBDA (HASHARRAY HASHFILE TESTFN)         (* cdl "25-Oct-85 08:25")
    (DECLARE (SPECVARS HASHARRAY HASHFILE TESTFN))
    (LET (REOPEN)
      (DECLARE (SPECVARS REOPEN))
      [if (HASHFILEP HASHFILE)
	  then (SETQ REOPEN T)
	else (SETQ HASHFILE (CREATEHASHFILE HASHFILE NIL NIL
					    (HARRAYPROP HASHARRAY
							'NUMKEYS]
      [RESETLST (RESETSAVE NIL (BQUOTE (CLOSEHASHFILE , HASHFILE , REOPEN)))
		(MAPHASH HASHARRAY
			 (FUNCTION (LAMBDA (VALUE KEY)
			     (if (OR (NULL TESTFN)
				     (APPLY* TESTFN KEY VALUE HASHARRAY 
					     HASHFILE))
				 then (PUTHASHFILE KEY VALUE HASHFILE]
      (if REOPEN
	  then HASHFILE
	else (with HashFile HASHFILE File])

(HASHFILE.TO.HASHARRAY
  [LAMBDA (HASHFILE HASHARRAY TESTFN)         (* cdl "25-Oct-85 08:29")
    (DECLARE (SPECVARS HASHFILE HASHARRAY TESTFN))
    (LET (REOPEN)
      (DECLARE (SPECVARS REOPEN))
      [if (HASHFILEP HASHFILE)
	  then (SETQ REOPEN T)
	else (SETQ HASHFILE (OPENHASHFILE HASHFILE 'INPUT]
      [if (NULL HASHARRAY)
	  then (SETQ HASHARRAY (with HashFile HASHFILE (HASHARRAY #Entries]
      [RESETLST (RESETSAVE NIL (BQUOTE (CLOSEHASHFILE , HASHFILE , REOPEN)))
		(MAPHASHFILE HASHFILE
			     (FUNCTION (LAMBDA (KEY VALUE)
				 (if (OR (NULL TESTFN)
					 (APPLY* TESTFN KEY VALUE HASHFILE 
						 HASHARRAY))
				     then (PUTHASH KEY VALUE HASHARRAY]
      HASHARRAY])
)
(DECLARE: DONTCOPY 
[DECLARE: EVAL@COMPILE 

(RECORD HASHBUFFER (HASHARRAY HASHFILE ACCESS))
]
)
STOP