[elephant-devel] difference between get-instances-by-class and cursors

Aycan iRiCAN aycan.irican at core.gen.tr
Sat Apr 8 08:26:15 UTC 2006


Hi,

Firstly, I want to thank you again for this great project.

Let me ask some questions. What is the difference between using
get-instances-by-class and using cursors?

When I use get-instances-by-class I get every instance (including
deleted keys) of the class. But when I use cursors, I only get
existing keys.

HEDEE> (get-instances-by-class 'user)
(#<USER "test" 3353473039> #<USER "aycan" 3353182543>)
HEDEE> (remove-kv 5 *hedee-users*)
T
HEDEE> (get-instances-by-class 'user)
(#<USER "test" 3353473039> #<USER "aycan" 3353182543>)
HEDEE> (with-transaction ()
	 (with-btree-cursor (c *hedee-users*)
	   (loop
	    for (m k v) = (multiple-value-list
		           (cursor-first c))
	    then (multiple-value-list (cursor-next c))
	    while m      
	    collect v into users
	    finally (return (nreverse users)))))
(#<USER "aycan" 3353182543>)

Is it possible to completely remove a key from a btree?

Say I have a class named user (used above):

(defclass user ()
  ((id :accessor id :initarg :id :type integer
       :initform (next-id)
       :index t)
   (name :accessor name :initarg :name
	 :initform nil :index t)
   (epitaph :accessor epitaph :initarg :epitaph
	    :initform nil)
   (image-type :accessor image-type :initarg :image-type :type string
	       :initform nil)
   (timestamp :accessor timestamp :initarg :timestamp :type integer :index t
	      :initform (get-universal-time)))
  (:metaclass persistent-metaclass))

and I created secondary indices via:

(defun add-indices ()
  (with-transaction ()
    (add-index *hedee-users*
	       :index-name 'id :key-form '(lambda (s key value)
					   (declare (ignore s key))
					   (values t (id value))))
    (add-index *hedee-users*
	       :index-name 'name :key-form '(lambda (s key value)
					     (declare (ignore s key))
					     (values t (name value))))
    (add-index *hedee-users*
	       :index-name 'timestamp :key-form '(lambda (s key value)
						  (declare (ignore s key))
						  (values t (timestamp value))))))

I tried to get users with a timestamp around some delta (320000 in
below) via:

(get-instances-by-range 'user
                        (get-index *hedee-users* 'timestamp) 
                        (get-universal-time) 
                        (- (get-universal-time) 320000))

But I'm getting:

The value 3353473355 is not of type FIXNUM.

How can I query by range using a timestamp?

Best Regards,

-- 
Aycan iRiCAN
C0R3 Computer Security Group
http://www.core.gen.tr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/elephant-devel/attachments/20060408/33d5d4c9/attachment.sig>


More information about the elephant-devel mailing list