<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
<META NAME="GENERATOR" CONTENT="GtkHTML/3.3.2">
</HEAD>
<BODY>
Dear Aycan,<BR>
I believe you are describing a problem that in principle has an easy to understand solution:<BR>
<BR>
<U>The bigger the date object you are dealing with, the more individual Elephant objects you</U><BR>
<U>problaby want to use to represent it.</U><BR>
The problem is that one can make a legitimate design decision about when an object<BR>
which is not completely monolithic should go in one object, or many.<BR>
<BR>
Consider for example, strings about 100 bytes long. The string is a primitive object; <BR>
there is no reason to represent it as more than one object in the Elephant store. Now consider<BR>
a collection of about 10 strings. This collection could be represented as 10 elephant objects,<BR>
or 1 elephant object which happens to be a list (or some other collection) of objects.<BR>
<BR>
In the application I am working on, I use both techniques for relatively small collections.<BR>
That is, sometimes I store lists (of up to 100) strings directly into a single object. In other<BR>
cases, I would take the 100 objects and give them each a separate existence (like your<BR>
solution 1 below, sort of). I tend to be a bit cavalier with respect to performance until<BR>
it trips me up; so if you force me to draw a line I would say "Don't put more than 1000 objects<BR>
into an Elephant database as a single object." One could argue that this should be lower.<BR>
Here is how I would write these two different ideas:<BR>
(open-store *testbdb-spec*)<BR>
<BR>
(setq nodes (add-to-root 'nodes (make-indexed-btree)))<BR>
(dotimes (i 100) <BR>
(setf (get-value i nodes) (* i i)))<BR>
(ele::dump-btree nodes)<BR>
k 0 / v 0<BR>
....lots of lines deleted (98)<BR>
k 99 / v 9801<BR>
(setq nodelist nil)<BR>
<BR>
(dotimes (i 100)<BR>
(progn<BR>
(push (* i i) nodelist )<BR>
(add-to-root 'nodes nodelist)))<BR>
(get-from-root 'nodes)<BR>
(9801 9604 9409 9216 9025 8836 8649 8464 8281 8100 7921 7744 7569 7396 7225<BR>
7056 6889 6724 6561 6400 6241 6084 5929 5776 5625 5476 5329 5184 5041 4900<BR>
4761 4624 4489 4356 4225 4096 3969 3844 3721 3600 3481 3364 3249 3136 3025<BR>
2916 2809 2704 2601 2500 2401 2304 2209 2116 2025 1936 1849 1764 1681 1600<BR>
1521 1444 1369 1296 1225 1156 1089 1024 961 900 841 784 729 676 625 576 529<BR>
484 441 400 361 324 289 256 225 196 169 144 121 100 81 64 49 36 25 16 9 4 1 0)<BR>
T<BR>
ELE-TESTS> <BR>
<BR>
The real question is: would you rather change an item in this set by changing the <BR>
list, or by treating it as a btree?<BR>
As the list gets larger and larger, it becomes more and more reasonable to <BR>
user a btree, and less and less reasonable to use a giant list --- but even then,<BR>
never optimize until you have to.<BR>
<BR>
On Wed, 2006-04-19 at 22:47 +0300, Aycan iRiCAN wrote:
<BLOCKQUOTE TYPE=CITE>
<PRE>
<FONT COLOR="#000000">Hi,</FONT>
<FONT COLOR="#000000">What is the difference between 'using a btree for items' and 'using an</FONT>
<FONT COLOR="#000000">object to hold items'?</FONT>
<FONT COLOR="#000000">Say we have a node class. In the first method, I'm creating objects</FONT>
<FONT COLOR="#000000">and adding them to a btree.</FONT>
<FONT COLOR="#000000">(add-to-root 'nodes (make-indexed-btree))</FONT>
<FONT COLOR="#000000">(dolist (item (create-100-node))</FONT>
<FONT COLOR="#000000"> (setf (get-value 'key 'nodes) item))</FONT>
<FONT COLOR="#000000">Now I can use cursors and indexes to reach nodes. In the second</FONT>
<FONT COLOR="#000000">method, I'm using an objects slot to hold nodes.</FONT>
<FONT COLOR="#000000">(add-to-root 'nodes (make-instance 'node-container :nodes '()))</FONT>
<FONT COLOR="#000000">(dolist (item (create-100-node))</FONT>
<FONT COLOR="#000000"> (push item (nodes (get-from-root 'nodes))))</FONT>
<FONT COLOR="#000000">Because of ease of use and maintainability, we're thinking that the</FONT>
<FONT COLOR="#000000">second method is better than the first method. We can get a backup</FONT>
<FONT COLOR="#000000">with a single cl-store call, we can easily walk the structure</FONT>
<FONT COLOR="#000000">etc.</FONT>
<FONT COLOR="#000000">Any ideas?</FONT>
<FONT COLOR="#000000">Best Regards.</FONT>
<FONT COLOR="#000000">_______________________________________________</FONT>
<FONT COLOR="#000000">elephant-devel site list</FONT>
<FONT COLOR="#000000"><A HREF="mailto:elephant-devel@common-lisp.net">elephant-devel@common-lisp.net</A></FONT>
<FONT COLOR="#000000"><A HREF="http://common-lisp.net/mailman/listinfo/elephant-devel">http://common-lisp.net/mailman/listinfo/elephant-devel</A></FONT>
</PRE>
</BLOCKQUOTE>
</BODY>
</HTML>