line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: IDspaceSet.pm 2014-06-06 erick.antezana $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Module : IDspaceSet.pm |
4
|
|
|
|
|
|
|
# Purpose : A set of IDspaces. |
5
|
|
|
|
|
|
|
# License : Copyright (c) 2006-2014 by Erick Antezana. All rights reserved. |
6
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
7
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
# Contact : Erick Antezana |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
package OBO::Util::IDspaceSet; |
11
|
|
|
|
|
|
|
# TODO This class is identical to OBO::Util::SynonymTypeDefSet |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @ISA = qw(OBO::Util::Set); |
14
|
8
|
|
|
8
|
|
1364
|
use OBO::Util::Set; |
|
8
|
|
|
|
|
52
|
|
|
8
|
|
|
|
|
232
|
|
15
|
|
|
|
|
|
|
|
16
|
8
|
|
|
8
|
|
34
|
use strict; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
207
|
|
17
|
8
|
|
|
8
|
|
41
|
use warnings; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
2568
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head2 contains |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Usage - $set->contains() |
22
|
|
|
|
|
|
|
Returns - true if this set contains the given element |
23
|
|
|
|
|
|
|
Args - the element (OBO::Core::IDspace) to be checked |
24
|
|
|
|
|
|
|
Function - checks if this set constains the given element |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
sub contains { |
28
|
57
|
|
|
57
|
1
|
114
|
my $self = shift; |
29
|
57
|
|
|
|
|
47
|
my $result = 0; |
30
|
57
|
50
|
|
|
|
97
|
if (@_){ |
31
|
57
|
|
|
|
|
51
|
my $target = shift; |
32
|
|
|
|
|
|
|
|
33
|
57
|
|
|
|
|
47
|
foreach my $ele (@{$self->{SET}}){ |
|
57
|
|
|
|
|
103
|
|
34
|
88
|
100
|
|
|
|
155
|
if ($target->equals($ele)) { |
35
|
21
|
|
|
|
|
13
|
$result = 1; |
36
|
21
|
|
|
|
|
28
|
last; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
57
|
|
|
|
|
141
|
return $result; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 equals |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Usage - $set->equals() |
46
|
|
|
|
|
|
|
Returns - true or false |
47
|
|
|
|
|
|
|
Args - the set (OBO::Util::IDspaceSet) to compare with |
48
|
|
|
|
|
|
|
Function - tells whether this set is equal to the given one |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=cut |
51
|
|
|
|
|
|
|
sub equals { |
52
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
53
|
1
|
|
|
|
|
1
|
my $result = 0; # I guess they'are NOT identical |
54
|
1
|
50
|
|
|
|
3
|
if (@_) { |
55
|
1
|
|
|
|
|
2
|
my $other_set = shift; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
2
|
my %count = (); |
58
|
1
|
|
|
|
|
1
|
my @this = map ({scalar $_;} @{$self->{SET}}); |
|
4
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
3
|
|
59
|
1
|
|
|
|
|
3
|
my @that = map ({scalar $_;} $other_set->get_set()); |
|
0
|
|
|
|
|
0
|
|
60
|
|
|
|
|
|
|
|
61
|
1
|
50
|
|
|
|
4
|
if ($#this == $#that) { |
62
|
0
|
|
|
|
|
0
|
foreach (@this, @that) { |
63
|
0
|
|
|
|
|
0
|
$count{$_}++; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
0
|
foreach my $count (sort values %count) { |
66
|
0
|
0
|
|
|
|
0
|
if ($count != 2) { |
67
|
0
|
|
|
|
|
0
|
$result = 0; |
68
|
0
|
|
|
|
|
0
|
last; |
69
|
|
|
|
|
|
|
} else { |
70
|
0
|
|
|
|
|
0
|
$result = 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
1
|
|
|
|
|
3
|
return $result; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 remove |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Usage - $set->remove($element) |
81
|
|
|
|
|
|
|
Returns - the removed element |
82
|
|
|
|
|
|
|
Args - the element (OBO::Core::IDspace) to be removed |
83
|
|
|
|
|
|
|
Function - removes an element from this set |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
sub remove { |
87
|
3
|
|
|
3
|
1
|
8
|
my $self = shift; |
88
|
3
|
|
|
|
|
4
|
my $result = undef; |
89
|
3
|
50
|
|
|
|
9
|
if (@_) { |
90
|
3
|
|
|
|
|
3
|
my $ele = shift; |
91
|
3
|
100
|
|
|
|
12
|
if ($self->size() > 0) { |
92
|
2
|
|
|
|
|
3
|
for (my $i = 0; $i < scalar(@{$self->{SET}}); $i++){ |
|
5
|
|
|
|
|
10
|
|
93
|
5
|
|
|
|
|
5
|
my $e = ${$self->{SET}}[$i]; |
|
5
|
|
|
|
|
6
|
|
94
|
5
|
100
|
|
|
|
8
|
if ($ele->equals($e)) { |
95
|
2
|
100
|
|
|
|
5
|
if ($self->size() > 1) { |
|
|
50
|
|
|
|
|
|
96
|
1
|
|
|
|
|
1
|
my $first_elem = shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
3
|
|
97
|
1
|
|
|
|
|
1
|
${$self->{SET}}[$i-1] = $first_elem; |
|
1
|
|
|
|
|
2
|
|
98
|
|
|
|
|
|
|
} elsif ($self->size() == 1) { |
99
|
1
|
|
|
|
|
2
|
shift (@{$self->{SET}}); |
|
1
|
|
|
|
|
2
|
|
100
|
|
|
|
|
|
|
} |
101
|
2
|
|
|
|
|
3
|
$result = $ele; |
102
|
2
|
|
|
|
|
2
|
last; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
3
|
|
|
|
|
6
|
return $result; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
__END__ |