User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

cl:functions:hash-table-count [2019/07/14 17:00]
cl:functions:hash-table-count [2019/10/19 17:00] (current)
Line 1: Line 1:
 +====== Function HASH-TABLE-COUNT ======
 +
 +====Syntax====
 +  * **hash-table-count** //​hash-table//​ → //count//
 +
 +====Arguments and Values====
 +  * //​hash-table//​ - a //​[[CL:​Glossary:​hash table]]//.
 +  * //count// - a non-negative //​[[CL:​Glossary:​integer]]//​.
 +
 +====Description====
 +Returns the number of entries in the //​hash-table//​. If //​hash-table//​ has just been created or newly cleared (see **[[CL:​Functions:​clrhash]]**) the entry count is ''​0''​.
 +
 +====Examples====
 +<​blockquote>​
 +([[CL:​Macros:​defparameter]] *table* ([[CL:​Functions:​make-hash-table]])) <​r>​*TABLE*</​r>​
 +*table* <​r>#<​HASH-TABLE [[CL:​Functions:​EQL]] 0/120 32115135></​r>​
 +(hash-table-count *table*) <​r>​0</​r>​
 +([[CL:​Macros:​setf]] ([[CL:​Functions:​gethash]] 57 *table*) "​fifty-seven"​) <​r>"​fifty-seven"</​r>​
 +(hash-table-count *table*) <​r>​1</​r>​
 +(dotimes (i 100) 
 +  ([[CL:​Macros:​setf]] ([[CL:​Functions:​gethash]] i *table*) i)) <​r>​NIL</​r>​
 +(hash-table-count *table*) <​r>​100</​r>​
 +</​blockquote>​
 +
 +====Side Effects====
 +None.
 +
 +====Affected By====
 +**[[CL:​Functions:​clrhash]]**,​ **[[CL:​Functions:​remhash]]**,​ **([[CL:​Macros:​setf]] [[CL:​Functions:​gethash]])**
 +
 +====Exceptional Situations====
 +None.
 +
 +====See Also====
 +  * **[[CL:​Functions:​hash-table-size|Function HASH-TABLE-SIZE]]**
 +
 +====Notes====
 +The following relationships are functionally correct, although in practice using **[[CL:​Functions:​hash-table-count]]** is probably much faster:
 +
 +<​blockquote>​
 +(hash-table-count //​table//​) ​
 +  ≡ ([[CL:​Macros:​loop]] for value 
 +                          being the hash-values of //table//
 +                        count [[CL:​Constant Variables:​t]]) ​
 +  ≡ ([[CL:​Special Operators:​let]] ((total 0)) 
 +      ([[CL:​Functions:​maphash]] #'​([[CL:​Symbols:​lambda]] (key value) ​
 +                   ​([[CL:​Symbols:​declare]] ([[CL:​Declarations:​ignore]] key value)) ​
 +                   ​([[CL:​Macros:​incf]] total)) ​
 +               //​table//​) ​
 +      total)
 +</​blockquote>​