ハッシュ


with-hash-table-iterator

type: Macro
arguments: with-hash-table-iterator (MNAME HASH-TABLE) &body BODY
package: lisp
file: hash.l
ハッシュテーブルの要素を順番に返す関数を返してもらいます。

  MNAME      : 要素を順番に返す関数名を指定します。
               この関数は要素を列挙し終わるとnilを返します。
  HASH-TABLE : ハッシュテーブルを指定します。
  BODY       : フォームを記述します。

関数が順番に要素を返すので、loopを使ってnilが返るまで繰り返します。

使用例:
  (with-output-to-selected-buffer
    (with-hash-table-iterator (foo hsh)
      (loop
        (multiple-value-bind (f x y)
            (foo)
          (unless f (return))
          (format t "~S ~S~%" x y)))))

SeeAlso: maphash
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

remhash

type: Function
arguments: remhash KEY HASH-TABLE
package: lisp
file: builtin.l
ハッシュテーブルの中からキーが一致するものを削除します。

  KEY        : 削除するキーを指定します。
  HASH-TABLE : ハッシュテーブルを指定します。

一致するキーが存在すれば削除してtを返します。
なければnilを返します。

使用例:
  (setq hash-table (make-hash-table))
  => #<hash table>
  (setf (gethash 'a hash-table) 1)
  => 1
  (remhash 'b hash-table)
  => nil
  (remhash 'a hash-table)
  => t

[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

maphash

type: Function
arguments: maphash FUNCTION HASH-TABLE
package: lisp
file: hash.l
ハッシュテーブルの各要素を関数に渡します。

  FUNCTION   : キーと値を受け取る関数
  HASH-TABLE : ハッシュテーブルを指定します。

使用例:
  (setf (gethash #\a hsh) "Apple")  => "Apple"
  (setf (gethash #\b hsh) "Banana") => "Banana"
  (setf (gethash #\c hsh) "Cake")   => "Cake"
  (with-output-to-selected-buffer
    (maphash #'(lambda (x y) (format t "~S ~S~%"x y)) hsh))
  #\a "Apple"
  #\b "Banana"
  #\c "Cake"

SeeAlso: with-hash-table-iterator
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

make-hash-table

type: Function
arguments: make-hash-table &key :test :size :rehash-size :rehash-threshold
package: lisp
file: builtin.l
ハッシュテーブルを作成して返します。

  :test        : ハッシュテーブルのキーの等価関係。デフォルトは eql です。
                 指定可能な関数は、eq, eql, equal, equalp に限られます。
  :size        : ハッシュテーブルの初期サイズの目安。
                 この値よりも大きい素数、または 2, 3, 5, 7 で割れない値
                 に設定されます。
  :rehash-size : ハッシュテーブルのテーブルサイズを増加させる量の目安。
                 デフォルトは 1。現在のサイズ と :rehash-size を参考
                 に、より大きい素数、または 2, 3, 5, 7 で割れないサイズ
                 にします。
  :rehash-threshold
               : xyzzy では実装されていないようです。 (0.2.2.235 現在)
                 その代わり、テーブルの使用率が 80% を超えるとテーブル
                 を伸長します。

とりうる素数は以下の通りです。
      17, 47, 101, 149, 199, 307, 401, 499, 599, 701, 797, 907, 997,
      1103, 1499, 1999, 2999, 4001, 4999, 6007, 7001, 8009, 8999,
      10007, 19997, 29989, 39989, 49999, 59999, 70001, 79999, 90001, 99991

使用例:
  (setq hash (make-hash-table :size 3))
  => #<hashtable 51122492>

  (progn
    (setf (gethash #\C-0 hash) 0)
    (setf (gethash #\C-1 hash) 1)
    (setf (gethash #\C-2 hash) 2))
  => 2
  
  (gethash #\C-1 hash)
  => 1
      t

  (hash-table-size hash)
  => 17

  (hash-table-rehash-size hash)
  => 1

  (hash-table-test hash)
  => eql

SeeAlso: gethash
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

hash-table-test

type: Function
arguments: hash-table-test HASH-TABLE
package: lisp
file: builtin.l
ハッシュテーブルのキーを比較する関数を返します。

  HASH-TABLE : ハッシュテーブルを指定します。

使用例:
  (hash-table-test hash-table)
  => eql

[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

hash-table-size

type: Function
arguments: hash-table-size HASH-TABLE
package: lisp
file: builtin.l
ハッシュテーブルの現在の大きさを返します。

  HASH-TABLE : ハッシュテーブルを指定します。

SeeAlso: hash-table-count
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

hash-table-rehash-size

type: Function
arguments: hash-table-rehash-size HASH-TABLE
package: lisp
file: builtin.l
ハッシュテーブルの現在のrehash-sizeを返します。

  HASH-TABLE : ハッシュテーブルを指定します。

[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

hash-table-p

type: Function
arguments: hash-table-p OBJECT
package: lisp
file: builtin.l
オブジェクトがハッシュテーブルかどうかを返します。

  OBJECT : 判定するオブジェクトを指定します。

  (hash-table-p x) == (typep x 'hash-table)

[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

hash-table-count

type: Function
arguments: hash-table-count HASH-TABLE
package: lisp
file: builtin.l
ハッシュテーブルの要素数を返します。

  HASH-TABLE : ハッシュテーブルを指定します。

SeeAlso: hash-table-size
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

gethash-region

type: Function
arguments: gethash-region FROM TO HASHTABLE &optional DEFAULT
package: editor
file: builtin.l
リージョンの文字列をハッシュテーブルから取得します。
(buffer-substring FROM TO)してから(gethash ... HASHTABLE)するようなものです。

SeeAlso: gethash
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

gethash

type: Function
arguments: gethash KEY HASH-TABLE &optional DEFAULT
package: lisp
file: builtin.l
ハッシュテーブルの中からキーが一致するものを返します。

  KEY        : 検索するキーを指定します。
  HASH-TABLE : ハッシュテーブルを指定します。

使用例:
  (setq hash-table (make-hash-table))
  => #<hash table>
  (gethash 'a hash-table)
  => nil
  (setf (gethash 'a hash-table) 1)
  => 1
  (gethash 'a hash-table)
  => 1

  (setq h (make-hash-table :test #'equalp))
  (setf (gethash "body" h) '(a b c))
  (gethash "BODY" h)

SeeAlso: maphash
[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]

clrhash

type: Function
arguments: clrhash HASH-TABLE
package: lisp
file: builtin.l
ハッシュテーブルの全要素を削除します。

  HASH-TABLE : ハッシュテーブルを指定します。

[ Intro | 目次 | 索引 | 目的別 | ハッシュ ]