The cl-custom-hash-table Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-custom-hash-table Reference Manual

This is the cl-custom-hash-table Reference Manual, version 0.3, generated automatically by Declt version 2.4 "Will Decker" on Wed Jun 20 11:03:02 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

CL-CUSTOM-HASH-TABLE: Custom hash tables for Common Lisp

Introduction

CL-CUSTOM-HASH-TABLE allows creation and use of "custom hash tables". Custom hash tables can use arbitrary TEST/HASH functions, in addition to the TEST functions allowed by the standard (EQ, EQL, EQUAL and EQUALP).

This library is primarily a compatibility layer, unifying how to create these hash table in different Lisp implementations. Furthermore this library provides a simple yet fully functional fall-back solution for implementations that don't support this functionality natively (yet).

License

CL-CUSTOM-HASH-TABLE is released under a BSD-like license, see the ASD file.

Compatibility

This library does not shadow symbols in the COMMON-LISP package. It does require that all access to (potential) custom hash tables is lexical wrapped in a WITH-CUSTOM-HASH-TABLE form (see example below).

The standard hash table related functions are supported:

Hash table iteration using LOOP (using HASH-KEY or HASH-VALUE) is not supported in Lisp implementations where the fall-back solution is used, therefore cannot be used in core that is supposed to be portable.

In the fall-back solution HASH-TABLE-COUNT returns the correct number of entries, but HASH-TABLE-SIZE returns the size of the underlying helper hash table which might be lower than HASH-TABLE-COUNT. Functions HASH-TABLE-REHASH-SIZE and HASH-TABLE-REHASH-THRESHOLD also refer to that helper hash table.

The fall-back solution is not thread-safe. The native implementation may or may not be.

Supported implementations

See the build status on Travis-CI, and the coverage status on Coveralls:

| Common Lisp Implementation | Native | Fallback | |:-:|:-:|:-:| | ABCL | n/a | Build Status | | Allegro CL | Build Status | Build Status | | Clozure CL | Build Status | Build Status | | CLISP | n/a | Build Status | | CMUCL | ? | ? | | ECL | n/a | Build Status | | LispWorks | ? | ? | | SBCL | Build Status | Build Status Coverage Status |

Example

Custom TEST and HASH functions:

 (defun foo-equal-p (x y) (= x y))
 (defun foo-hash (x) (mod x 10))

Define the hash table type:

 (use-package :cl-custom-hash-table)

 (define-custom-hash-table-constructor make-foo-ht
    :test foo-equal-p :hash-function foo-hash)

Now MAKE-FOO-HT is a function that will create the custom hash table:

 (defparameter *foo-ht* (make-foo-ht)
   "Hash table using FOO-HASH and FOO-EQUAL-P")

You can trace your test/hash functions to check they are really getting called later:

 (trace foo-equal-p foo-hash)

Use WITH-CUSTOM-HASH-TABLE around access to the hash table. This ensures functions GETHASH, REMHASH and MAPHASH do the right thing. If you forget this, your code will not work in implementations that don't support custom TEST/HASH functions natively!

 (with-custom-hash-table
    (setf (gethash 1 *foo-ht*) 1
          (gethash 10 *foo-ht*) 10
          (gethash 2 *foo-ht*) 2)
    (maphash (lambda (k v) 
                (format t "~A: ~A~%" k v)
 	            (remhash k *foo-ht*))
             *foo-ht*))

Implementation details

Several Lisp implementations already support custom TEST and HASH arguments for MAKE-HASH-TABLE. This library is a small wrapper around the vendor-specific extensions. (Allegro CL, CCL, CMUCL, LispWorks, SBCL)

In other Lisp implementations (ABCL, CLISP, ECL) a fall-back solution is used:

How does this compare to genhash?


Next: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-custom-hash-table

Author

Willem Broekema

License

Copyright (c) 2010-2014, Willem Broekema All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Long Description

This library allows creation of hash tables with arbitrary TEST/HASH functions,
in addition to the TEST functions allowed by the standard (EQ, EQL, EQUAL and EQUALP), even in implementations that don’t support this functionality directly.

Version

0.3

Source

cl-custom-hash-table.asd (file)

Components

Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 cl-custom-hash-table.asd

Location

cl-custom-hash-table.asd

Systems

cl-custom-hash-table (system)


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.2 cl-custom-hash-table/package.lisp

Parent

cl-custom-hash-table (system)

Location

package.lisp

Packages

cl-custom-hash-table


Previous: , Up: Lisp files   [Contents][Index]

3.1.3 cl-custom-hash-table/custom-hash-table.lisp

Dependency

package.lisp (file)

Parent

cl-custom-hash-table (system)

Location

custom-hash-table.lisp

Exported Definitions
Internal Definitions

checking-reader-conditionals (macro)


Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 cl-custom-hash-table

Source

package.lisp (file)

Use List

common-lisp

Exported Definitions
Internal Definitions

checking-reader-conditionals (macro)


Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Macros

Macro: define-custom-hash-table-constructor MAKE &key TEST HASH-FUNCTION

Generate a function that can be used to create a new hash table that uses the given TEST and HASH-FUNCTION.
For example: (DEFINE-CUSTOM-HASH-TABLE-CONSTRUCTOR MAKE-FOO-HT :TEST FOO-EQUAL-P :HASH-FUNCTION FOO-HASH)
defines function (MAKE-FOO-HT &REST OPTIONS).
OPTIONS are passed on to MAKE-HASH-TABLE if the platform supports custom hash tables natively, and ignored otherwise.

Package

cl-custom-hash-table

Source

custom-hash-table.lisp (file)

Macro: with-custom-hash-table &body BODY

Wrap BODY in an environment where access to custom hash-tables (GET-HASH etc) works as expected.
This macro is a no-op in Lisp implementations that support custom hash-tables natively, but it is
required in implementations where the fallback solution is used (*FEATURES* value :CUSTOM-HASH-TABLE-FALLBACK)

Package

cl-custom-hash-table

Source

custom-hash-table.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Macros

Macro: checking-reader-conditionals &body BODY

Break unless the body contains exactly one form. Inspired by code from Steve Haflich.

Package

cl-custom-hash-table

Source

custom-hash-table.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
cl-custom-hash-table.asd: The cl-custom-hash-table<dot>asd file
cl-custom-hash-table/custom-hash-table.lisp: The cl-custom-hash-table/custom-hash-table<dot>lisp file
cl-custom-hash-table/package.lisp: The cl-custom-hash-table/package<dot>lisp file

F
File, Lisp, cl-custom-hash-table.asd: The cl-custom-hash-table<dot>asd file
File, Lisp, cl-custom-hash-table/custom-hash-table.lisp: The cl-custom-hash-table/custom-hash-table<dot>lisp file
File, Lisp, cl-custom-hash-table/package.lisp: The cl-custom-hash-table/package<dot>lisp file

L
Lisp File, cl-custom-hash-table.asd: The cl-custom-hash-table<dot>asd file
Lisp File, cl-custom-hash-table/custom-hash-table.lisp: The cl-custom-hash-table/custom-hash-table<dot>lisp file
Lisp File, cl-custom-hash-table/package.lisp: The cl-custom-hash-table/package<dot>lisp file

Jump to:   C   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   C   D   M   W  
Index Entry  Section

C
checking-reader-conditionals: Internal macros

D
define-custom-hash-table-constructor: Exported macros

M
Macro, checking-reader-conditionals: Internal macros
Macro, define-custom-hash-table-constructor: Exported macros
Macro, with-custom-hash-table: Exported macros

W
with-custom-hash-table: Exported macros

Jump to:   C   D   M   W  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables


Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

Jump to:   C   P   S  
Index Entry  Section

C
cl-custom-hash-table: The cl-custom-hash-table system
cl-custom-hash-table: The cl-custom-hash-table package

P
Package, cl-custom-hash-table: The cl-custom-hash-table package

S
System, cl-custom-hash-table: The cl-custom-hash-table system

Jump to:   C   P   S