ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Tree-M/M.xs
Revision: 1.5
Committed: Wed May 23 02:11:14 2001 UTC (23 years, 2 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +6 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 extern "C" {
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 }
6
7 #include "PMT.h"
8
9 typedef PMT Tree__M__MT;
10 typedef double *Key;
11
12 static double *
13 sv2c(SV *sv, int ndims)
14 {
15 if (!SvROK (sv) || SvTYPE (SvRV (sv)) != SVt_PVAV)
16 croak ("Tree::M: key must be array reference");
17
18 AV *av = (AV *)SvRV (sv);
19
20 if (av_len (av) != ndims -1)
21 croak ("Tree::M: illegal key, expected %d elements, found %d",
22 ndims, av_len (av) + 1);
23
24 double *k = new double [ndims];
25
26 for (int i = ndims; i--; )
27 k[i] = SvNV (*av_fetch (av, i, 1));
28
29 return k;
30 }
31
32 static SV *
33 c2sv(double *k, int ndims)
34 {
35 AV *av = newAV ();
36
37 av_extend (av, ndims);
38 for (int i = ndims; i--; )
39 av_store (av, i, newSVnv (k[i]));
40
41 return newRV_noinc ((SV *)av);
42 }
43
44 static AV *searchres;
45
46 void add_result(int data, double *k, int ndims)
47 {
48 AV *r = newAV ();
49
50 av_push (r, c2sv (k, ndims));
51 av_push (r, newSViv (data));
52
53 av_push (searchres, newRV_noinc ((SV *)r));
54 }
55
56 MODULE = Tree::M PACKAGE = Tree::M
57
58 PROTOTYPES: ENABLE
59
60 PMT *
61 _new(class, ndims, min = 0.0, max = 255.0, steps = 256.0, pagesize = 4096)
62 int ndims
63 double min
64 double max
65 double steps
66 unsigned int pagesize
67 CODE:
68 RETVAL = new PMT(ndims, min, max, steps, pagesize);
69 OUTPUT:
70 RETVAL
71
72 void
73 PMT::create(path)
74 char * path
75
76 void
77 PMT::open(path)
78 char * path
79
80 void
81 PMT::insert(k, idx = 0)
82 SV * k
83 int idx
84 C_ARGS:
85 sv2c(k, THIS->ndims), idx
86
87 double
88 PMT::distance(k1, k2)
89 SV * k1
90 SV * k2
91 C_ARGS:
92 sv2c(k1, THIS->ndims), sv2c(k2, THIS->ndims)
93
94 SV *
95 PMT::range(k, r)
96 SV * k
97 double r
98 CODE:
99 searchres = newAV ();
100 THIS->range(sv2c(k, THIS->ndims), r);
101 RETVAL = newRV_noinc ((SV *)searchres);
102 OUTPUT:
103 RETVAL
104
105 SV *
106 PMT::top(k, n)
107 SV * k
108 int n
109 CODE:
110 searchres = newAV ();
111 THIS->top(sv2c(k, THIS->ndims), n);
112 RETVAL = newRV_noinc ((SV *)searchres);
113 OUTPUT:
114 RETVAL
115
116 void
117 PMT::sync()
118
119 int
120 PMT::maxlevel()
121
122 void
123 PMT::DESTROY()
124