/[cl-table]/iterator.lisp
ViewVC logotype

Contents of /iterator.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Thu Feb 9 15:45:13 2012 UTC (2 years, 2 months ago) by rklochkov
File size: 1956 byte(s)
Initial release
1 (in-package :cl-table)
2
3 (defstruct (iter-row (:include row))
4 "Iterator element"
5 (id 0 :type fixnum)
6 (children-vector #() :type (vector iter-row)))
7
8 ;; We need vector of top rows and vector of all rows (to have integer -> row)
9 ;; And we have to store it with the table or else we have independent vars
10 ;; for a table
11
12 (defstruct iter-table
13 (all #() :type (vector iter-row))
14 (top #() :type (vector iter-row)))
15
16
17 (defun make-iterator (table)
18 "Returns array of iter-row"
19 (let (res visited (res-len -1))
20 (declare (special visited))
21 (labels ((to-vector (l)
22 (coerce (nreverse l) 'vector))
23 (visit-row (row)
24 (declare (special visited))
25 (let* ((children
26 (let (visited)
27 (declare (special visited))
28 (map-table-row #'visit-row row)
29 (to-vector visited)))
30 (new-row (make-iter-row
31 :parent (row-parent row)
32 :table (row-table row)
33 :children-vector children
34 :children (row-children row)
35 :id (incf res-len)
36 :num (row-num row)
37 :data (row-data row))))
38 (push new-row res)
39 (push new-row visited))))
40 (map-table #'visit-row table)
41 (make-iter-table :all (to-vector res) :top (to-vector visited)))))
42
43 (defun aref* (array index)
44 (when (< -1 index (array-dimension array 0))
45 (aref array index)))
46
47 (defmethod path->row ((iter-table iter-table) path)
48 (when path
49 (path->row (aref* (iter-table-top iter-table) (car path)) (cdr path))))
50
51 (defmethod path->row ((iter-row iter-row) path)
52 (if path
53 (path->row (aref* (iter-row-children-vector iter-row) (car path))
54 (cdr path))
55 iter-row))

  ViewVC Help
Powered by ViewVC 1.1.5