root/trunk/perl/lib/Cornea/StorageNodeList.pm

Revision 9, 0.8 kB (checked in by jesus, 5 years ago)

nodes appear to work

Line 
1 package Cornea::StorageNodeList;
2 use strict;
3
4 sub new {
5   my $class = shift;
6   $class = ref($class) ? ref $class : $class;
7   bless {}, $class;
8 }
9
10 sub items {
11   my $self = shift;
12   return values (%$self);
13 }
14
15 sub remove {
16   my $self = shift;
17   my $node = shift;
18   delete $self->{$node->fqdn()};
19 }
20
21 sub add {
22   my $self = shift;
23   my $node = shift;
24   $self->{$node->fqdn()} = $node;
25 }
26
27 sub count {
28   my $self = shift;
29   return scalar(keys %$self);
30 }
31
32 sub removeWithin {
33   my $self = shift;
34   my $reference = shift;
35   my $distance = shift;
36   foreach my $n (values %$self) {
37     foreach my $r ($reference->items()) {
38       if($r->distance($n) < $distance) {
39         $self->remove($n);
40         last;
41       }
42     }
43   }
44 }
45
46 sub copy {
47   my $self = shift;
48   my $copy = $self->new();
49   foreach my $n ($self->items) {
50     $copy->add($n);
51   }
52   return $copy;
53 }
54
55 1;
Note: See TracBrowser for help on using the browser.