… | |
… | |
2 | |
2 | |
3 | use Carp; |
3 | use Carp; |
4 | use DynaLoader; |
4 | use DynaLoader; |
5 | |
5 | |
6 | BEGIN { |
6 | BEGIN { |
7 | $VERSION = 0.01; |
7 | $VERSION = 0.02; |
8 | @ISA = qw(DynaLoader); |
8 | @ISA = qw(DynaLoader); |
9 | bootstrap Tree::M, $VERSION; |
9 | bootstrap Tree::M, $VERSION; |
10 | } |
10 | } |
11 | |
11 | |
12 | =head1 NAME |
12 | =head1 NAME |
13 | |
13 | |
14 | Tree::M - implement M-trees for efficient "multimedia-searched" |
14 | Tree::M - implement M-trees for efficient "metric/multimedia-searches" |
15 | |
15 | |
16 | =head1 SYNOPSIS |
16 | =head1 SYNOPSIS |
17 | |
17 | |
18 | use Tree::M; |
18 | use Tree::M; |
19 | |
19 | |
… | |
… | |
48 | |
48 | |
49 | =head2 THE Tree::M CLASS |
49 | =head2 THE Tree::M CLASS |
50 | |
50 | |
51 | =over 4 |
51 | =over 4 |
52 | |
52 | |
53 | =item $M = new Tree::M ndims, min, max, steps |
53 | =item $M = new Tree::M arg => value, ... |
54 | |
54 | |
55 | Creates a new M-Tree. Before it can be used you have to call one of the |
55 | Creates a new M-Tree. Before it can be used you have to call one of the |
56 | C<create> or C<open> methods. |
56 | C<create> or C<open> methods below. |
57 | |
57 | |
|
|
58 | ndims => integer |
58 | ndims the number of dimensions each vector has |
59 | the number of dimensions each vector has |
|
|
60 | |
|
|
61 | range => [min, max, steps] |
59 | min the lowest allowable scalar value in each dimension |
62 | min the lowest allowable scalar value in each dimension |
60 | max the maximum allowable number |
63 | max the maximum allowable number |
61 | steps the number of discrete steps (used when stored externally) |
64 | steps the number of discrete steps (used when stored externally) |
|
|
65 | |
|
|
66 | pagesize => integer |
|
|
67 | the size of one page on underlying storage. usually 4096, but |
|
|
68 | large objects (ndims > 20 or so) might want to increase this |
62 | |
69 | |
63 | Example: create an M-Tree that stores 8-bit rgb-values: |
70 | Example: create an M-Tree that stores 8-bit rgb-values: |
64 | |
71 | |
65 | $M = new Tree::M 3, 0, 255, 256; |
72 | $M = new Tree::M ndims => 3, range => [0, 255, 256]; |
66 | |
73 | |
67 | Example: create an M-Tree that stores coordinates from -1..1 with 100 different steps: |
74 | Example: create an M-Tree that stores coordinates from -1..1 with 100 different steps: |
68 | |
75 | |
69 | $M = new Tree::M 2, -1, 1, 100; |
76 | $M = new Tree::M ndims => 2, range => [-1, 1, 100]; |
70 | |
77 | |
71 | =item $M->open(path) |
78 | =item $M->open(path) |
72 | |
79 | |
73 | =item $M->create($path) |
80 | =item $M->create($path) |
74 | |
81 | |
… | |
… | |
78 | |
85 | |
79 | =item $M->insert(\@v, $data) |
86 | =item $M->insert(\@v, $data) |
80 | |
87 | |
81 | Insert a vector (given by an array reference) into the index and associate |
88 | Insert a vector (given by an array reference) into the index and associate |
82 | it with the value C<$data> (a 32-bit integer). |
89 | it with the value C<$data> (a 32-bit integer). |
|
|
90 | |
|
|
91 | =item $M->sync |
|
|
92 | |
|
|
93 | Synchronize the data file with memory. Useful after calling C<insert> to |
|
|
94 | ensure the data actually reaches stable storage. |
83 | |
95 | |
84 | =item $res = $M->range(\@v, $radius) |
96 | =item $res = $M->range(\@v, $radius) |
85 | |
97 | |
86 | Search all entries not farther away from C<@v> then C<$radius> and return |
98 | Search all entries not farther away from C<@v> then C<$radius> and return |
87 | an arrayref containing the searchresults. |
99 | an arrayref containing the searchresults. |
… | |
… | |
107 | Return the maximum height of the tree (usually a small integer specifying |
119 | Return the maximum height of the tree (usually a small integer specifying |
108 | the length of the path from the root to the farthest leaf) |
120 | the length of the path from the root to the farthest leaf) |
109 | |
121 | |
110 | =cut |
122 | =cut |
111 | |
123 | |
|
|
124 | sub new { |
|
|
125 | my $class = shift; |
|
|
126 | my %a = @_; |
|
|
127 | $class->_new( |
|
|
128 | $a{ndims}, |
|
|
129 | $a{range}[0], |
|
|
130 | $a{range}[1], |
|
|
131 | $a{range}[2], |
|
|
132 | $a{pagesize}, |
|
|
133 | ); |
|
|
134 | } |
|
|
135 | |
112 | =back |
136 | =back |
113 | |
137 | |
114 | =head1 BUGS |
138 | =head1 BUGS |
115 | |
139 | |
116 | Inserting too many duplicate keys into the tree cause the C++ library to |
140 | Inserting too many duplicate keys into the tree cause the C++ library to |