From: ueno Date: Fri, 18 Nov 2005 13:50:36 +0000 (+0000) Subject: * riece-cache.el: Renamed from riece-lru.el. X-Git-Tag: riece-2_0_2~16 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27eac3ec788c4ad4c52aa3eb1ee24d2e9477db6f;p=elisp%2Friece.git * riece-cache.el: Renamed from riece-lru.el. --- diff --git a/lisp/COMPILE b/lisp/COMPILE index 4e5ad0e..1015728 100644 --- a/lisp/COMPILE +++ b/lisp/COMPILE @@ -14,7 +14,7 @@ riece-addon-modules riece-addon riece-ruby - riece-lru + riece-cache riece-mode ;; riece-identity -+-> riece-channel diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4675df6..044bdd4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,9 @@ 2005-11-18 Daiki Ueno + * riece-cache.el: Renamed from riece-lru.el. + +2005-11-18 Daiki Ueno + * riece-user.el: Require 'riece-lru. (riece-find-user): Increase priority of given username in riece-user-lru. diff --git a/lisp/riece-cache.el b/lisp/riece-cache.el new file mode 100644 index 0000000..1a820a0 --- /dev/null +++ b/lisp/riece-cache.el @@ -0,0 +1,165 @@ +;;; riece-cache.el --- LRU cache management +;; Copyright (C) 1998-2005 Daiki Ueno + +;; Author: Daiki Ueno +;; Created: 1998-09-28 +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Code: + +(defun riece-cache-make-node (key value &optional previous next) + "Make riece-cache-node object." + (vector key value previous next)) + +(defun riece-cache-node-key (node) + "Return key of NODE." + (aref node 0)) + +(defun riece-cache-node-value (node) + "Return value of NODE." + (aref node 1)) + +(defun riece-cache-node-set-value (node value) + "Set value of NODE to VALUE." + (aset node 1 value)) + +(defun riece-cache-node-next (node) + "Return next of NODE." + (aref node 3)) + +(defun riece-cache-node-set-next (node next) + "Set next of NODE to NEXT." + (aset node 3 next)) + +(defun riece-cache-node-previous (node) + "Return previous of NODE." + (aref node 2)) + +(defun riece-cache-node-set-previous (node previous) + "Set previous of NODE to PREVIOUS." + (aset node 2 previous)) + +(defun riece-cache-make-map (max-length) + "Make riece-cache-map object." + (vector max-length (make-vector (* max-length 2) 0) 0 nil nil)) + +(defun riece-cache-map-max-length (map) + "Return max-length of MAP." + (aref map 0)) + +(defun riece-cache-map-hash-obarray (map) + "Return hash-obarray of MAP." + (aref map 1)) + +(defun riece-cache-map-hash-length (map) + "Return hash-length of MAP." + (aref map 2)) + +(defun riece-cache-map-set-hash-length (map hash-length) + "Set hash-length of MAP to HASH-LENGTH." + (aset map 2 hash-length)) + +(defun riece-cache-map-first (map) + "Return first of MAP." + (aref map 3)) + +(defun riece-cache-map-set-first (map first) + "Set first of MAP to FIRST." + (aset map 3 first)) + +(defun riece-cache-map-last (map) + "Return last of MAP." + (aref map 4)) + +(defun riece-cache-map-set-last (map last) + "Set last of MAP to LAST." + (aset map 4 last)) + +(defalias 'riece-make-cache 'riece-cache-make-map) + +(defun riece-cache-contains (map key) + (intern-soft key (riece-cache-map-hash-obarray map))) + +(defun riece-cache-get (map key) + (let ((node (riece-cache-get-node map key))) + (if node + (riece-cache-node-value node)))) + +(defun riece-cache-get-node (map key) + (let ((symbol (intern-soft key (riece-cache-map-hash-obarray map))) + previous next last node) + (when symbol + (setq node (symbol-value symbol) + previous (riece-cache-node-previous node) + next (riece-cache-node-next node) + last (riece-cache-map-last map)) + (if previous + (riece-cache-node-set-next previous next)) + (if next + (riece-cache-node-set-previous next previous)) + (riece-cache-node-set-next node nil) + (riece-cache-node-set-previous node last) + (riece-cache-node-set-next last node) + (riece-cache-map-set-last map node) + (if (and (eq node (riece-cache-map-first map)) next) + (riece-cache-map-set-first map next)) + node))) + +(defun riece-cache-delete (map key) + (let ((symbol (intern-soft key (riece-cache-map-hash-obarray map))) + previous next node) + (when symbol + (setq node (symbol-value symbol) + previous (riece-cache-node-previous node) + next (riece-cache-node-next node)) + (if previous + (riece-cache-node-set-next previous next)) + (if next + (riece-cache-node-set-previous next previous)) + (if (eq (riece-cache-map-last map) node) + (riece-cache-map-set-last map previous)) + (if (eq (riece-cache-map-first map) node) + (riece-cache-map-set-first map next)) + (unintern symbol (riece-cache-map-hash-obarray map)) + (riece-cache-map-set-hash-length map (1- (riece-cache-map-hash-length map))) + (riece-cache-node-value node)))) + +(defun riece-cache-set (map key value) + (let ((node (riece-cache-get-node map key))) + (if node + (riece-cache-node-set-value node value) + (if (>= (riece-cache-map-hash-length map) + (riece-cache-map-max-length map)) + (riece-cache-delete map (riece-cache-node-key + (riece-cache-map-first map)))) + (setq node (riece-cache-make-node key value (riece-cache-map-last map) nil)) + (set (intern key (riece-cache-map-hash-obarray map)) node) + (riece-cache-map-set-hash-length map (1+ (riece-cache-map-hash-length map))) + (unless (riece-cache-map-first map) + (riece-cache-map-set-first map node)) + (if (riece-cache-map-last map) + (progn + (riece-cache-node-set-next (riece-cache-map-last map) node) + (riece-cache-node-set-previous node (riece-cache-map-last map)))) + (riece-cache-map-set-last map node)))) + +(provide 'riece-cache) + +;;; riece-cache.el ends here diff --git a/lisp/riece-lru.el b/lisp/riece-lru.el deleted file mode 100644 index 6c5cbbd..0000000 --- a/lisp/riece-lru.el +++ /dev/null @@ -1,137 +0,0 @@ -(defun riece-lru-make-node (key value &optional previous next) - "Make riece-lru-node object." - (vector key value previous next)) - -(defun riece-lru-node-key (node) - "Return key of NODE." - (aref node 0)) - -(defun riece-lru-node-value (node) - "Return value of NODE." - (aref node 1)) - -(defun riece-lru-node-set-value (node value) - "Set value of NODE to VALUE." - (aset node 1 value)) - -(defun riece-lru-node-next (node) - "Return next of NODE." - (aref node 3)) - -(defun riece-lru-node-set-next (node next) - "Set next of NODE to NEXT." - (aset node 3 next)) - -(defun riece-lru-node-previous (node) - "Return previous of NODE." - (aref node 2)) - -(defun riece-lru-node-set-previous (node previous) - "Set previous of NODE to PREVIOUS." - (aset node 2 previous)) - -(defun riece-lru-make-map (max-length) - "Make riece-lru-map object." - (vector max-length (make-vector (* max-length 2) 0) 0 nil nil)) - -(defun riece-lru-map-max-length (map) - "Return max-length of MAP." - (aref map 0)) - -(defun riece-lru-map-hash-obarray (map) - "Return hash-obarray of MAP." - (aref map 1)) - -(defun riece-lru-map-hash-length (map) - "Return hash-length of MAP." - (aref map 2)) - -(defun riece-lru-map-set-hash-length (map hash-length) - "Set hash-length of MAP to HASH-LENGTH." - (aset map 2 hash-length)) - -(defun riece-lru-map-first (map) - "Return first of MAP." - (aref map 3)) - -(defun riece-lru-map-set-first (map first) - "Set first of MAP to FIRST." - (aset map 3 first)) - -(defun riece-lru-map-last (map) - "Return last of MAP." - (aref map 4)) - -(defun riece-lru-map-set-last (map last) - "Set last of MAP to LAST." - (aset map 4 last)) - -(defalias 'riece-make-lru 'riece-lru-make-map) - -(defun riece-lru-contains (map key) - (intern-soft key (riece-lru-map-hash-obarray map))) - -(defun riece-lru-get (map key) - (let ((node (riece-lru-get-node map key))) - (if node - (riece-lru-node-value node)))) - -(defun riece-lru-get-node (map key) - (let ((symbol (intern-soft key (riece-lru-map-hash-obarray map))) - previous next last node) - (when symbol - (setq node (symbol-value symbol) - previous (riece-lru-node-previous node) - next (riece-lru-node-next node) - last (riece-lru-map-last map)) - (if previous - (riece-lru-node-set-next previous next)) - (if next - (riece-lru-node-set-previous next previous)) - (riece-lru-node-set-next node nil) - (riece-lru-node-set-previous node last) - (riece-lru-node-set-next last node) - (riece-lru-map-set-last map node) - (if (and (eq node (riece-lru-map-first map)) next) - (riece-lru-map-set-first map next)) - node))) - -(defun riece-lru-delete (map key) - (let ((symbol (intern-soft key (riece-lru-map-hash-obarray map))) - previous next node) - (when symbol - (setq node (symbol-value symbol) - previous (riece-lru-node-previous node) - next (riece-lru-node-next node)) - (if previous - (riece-lru-node-set-next previous next)) - (if next - (riece-lru-node-set-previous next previous)) - (if (eq (riece-lru-map-last map) node) - (riece-lru-map-set-last map previous)) - (if (eq (riece-lru-map-first map) node) - (riece-lru-map-set-first map next)) - (unintern symbol (riece-lru-map-hash-obarray map)) - (riece-lru-map-set-hash-length map (1- (riece-lru-map-hash-length map))) - (riece-lru-node-value node)))) - -(defun riece-lru-set (map key value) - (let ((node (riece-lru-get-node map key))) - (if node - (riece-lru-node-set-value node value) - (if (>= (riece-lru-map-hash-length map) - (riece-lru-map-max-length map)) - (riece-lru-delete map (riece-lru-node-key - (riece-lru-map-first map)))) - (setq node (riece-lru-make-node key value (riece-lru-map-last map) nil)) - (set (intern key (riece-lru-map-hash-obarray map)) node) - (riece-lru-map-set-hash-length map (1+ (riece-lru-map-hash-length map))) - (unless (riece-lru-map-first map) - (riece-lru-map-set-first map node)) - (if (riece-lru-map-last map) - (progn - (riece-lru-node-set-next (riece-lru-map-last map) node) - (riece-lru-node-set-previous node (riece-lru-map-last map)))) - (riece-lru-map-set-last map node)))) - -(provide 'riece-lru) \ No newline at end of file diff --git a/lisp/riece-misc.el b/lisp/riece-misc.el index ebb9234..bc06db1 100644 --- a/lisp/riece-misc.el +++ b/lisp/riece-misc.el @@ -32,7 +32,7 @@ (require 'riece-server) (require 'riece-user) (require 'riece-mode) -(require 'riece-lru) +(require 'riece-cache) (defun riece-get-buffer-create (name &optional init-major-mode) (let ((buffer (get-buffer name))) @@ -222,7 +222,7 @@ (setq identities (cons (riece-make-identity (symbol-name user) server-name) identities))) - (riece-lru-map-hash-obarray riece-user-lru)) + (riece-cache-map-hash-obarray riece-user-cache)) identities))) (defun riece-get-channels-on-server (server-name) diff --git a/lisp/riece-server.el b/lisp/riece-server.el index 4d8a1f3..4a64df1 100644 --- a/lisp/riece-server.el +++ b/lisp/riece-server.el @@ -29,7 +29,7 @@ (require 'riece-coding) ;riece-default-coding-system (require 'riece-identity) (require 'riece-compat) -(require 'riece-lru) +(require 'riece-cache) (eval-and-compile (defvar riece-server-keyword-map @@ -272,8 +272,8 @@ the `riece-server-keyword-map' variable." (make-local-variable 'riece-channel-obarray) (setq riece-channel-obarray (make-vector riece-channel-obarray-size 0)) (make-local-variable 'riece-coding-system) - (make-local-variable 'riece-user-lru) - (setq riece-user-lru (riece-make-lru riece-user-lru-max-size)) + (make-local-variable 'riece-user-cache) + (setq riece-user-cache (riece-make-cache riece-user-cache-max-size)) (buffer-disable-undo) (erase-buffer))) diff --git a/lisp/riece-user.el b/lisp/riece-user.el index fb4b261..3af38da 100644 --- a/lisp/riece-user.el +++ b/lisp/riece-user.el @@ -25,27 +25,27 @@ (require 'riece-identity) (require 'riece-mode) -(require 'riece-lru) +(require 'riece-cache) ;;; User object: (defun riece-find-user (name) "Get a user object named NAME from the server buffer." - (riece-lru-get riece-user-lru name) + (riece-cache-get riece-user-cache name) (let ((symbol (intern-soft (riece-identity-canonicalize-prefix name) riece-user-obarray))) (if symbol (symbol-value symbol)))) (defun riece-forget-user (name) - (riece-lru-delete riece-user-lru name) + (riece-cache-delete riece-user-cache name) (let ((symbol (intern-soft (riece-identity-canonicalize-prefix name)))) (when symbol (makunbound symbol) (unintern (symbol-name symbol) riece-user-obarray)))) (defun riece-rename-user (old-name new-name) - (riece-lru-delete riece-user-lru old-name) - (riece-lru-set riece-user-lru new-name new-name) + (riece-cache-delete riece-user-cache old-name) + (riece-cache-set riece-user-cache new-name new-name) (unless (equal (riece-identity-canonicalize-prefix old-name) (riece-identity-canonicalize-prefix new-name)) (let ((symbol (intern-soft (riece-identity-canonicalize-prefix old-name) @@ -68,7 +68,7 @@ away status, respectively." riece-user-obarray))) (if symbol (symbol-value symbol) - (riece-lru-set riece-user-lru name name) + (riece-cache-set riece-user-cache name name) (set (intern (riece-identity-canonicalize-prefix name) riece-user-obarray) (riece-make-user nil nil nil nil nil)))))