| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 1 | package Krawfish::Index::PostingsList; |
| Akron | 73ca245 | 2016-11-20 17:09:39 +0100 | [diff] [blame] | 2 | use Krawfish::Index::PostingPointer; |
| Akron | ded01ae | 2016-11-23 13:43:54 +0100 | [diff] [blame] | 3 | use Krawfish::Log; |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 4 | use strict; |
| 5 | use warnings; |
| Akron | 8781e6b | 2016-12-09 02:04:17 +0100 | [diff] [blame] | 6 | use constant DEBUG => 0; |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 7 | |
| 8 | # TODO: Use different PostingsList for different term types |
| Akron | 93271d8 | 2016-11-24 09:18:41 +0100 | [diff] [blame] | 9 | # |
| Akron | 33f1dcb | 2016-10-29 17:27:23 +0200 | [diff] [blame] | 10 | # TODO: Split postinglists, so they have different sizes, |
| Akron | 73ca245 | 2016-11-20 17:09:39 +0100 | [diff] [blame] | 11 | # that may be fragmented. |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 12 | |
| 13 | sub new { |
| Akron | 6e13a06 | 2017-01-13 11:55:28 +0100 | [diff] [blame] | 14 | my ($class, $index_file, $term, $term_id) = @_; |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 15 | bless { |
| 16 | term => $term, |
| Akron | 6e13a06 | 2017-01-13 11:55:28 +0100 | [diff] [blame] | 17 | term_id => $term_id, |
| Akron | ded01ae | 2016-11-23 13:43:54 +0100 | [diff] [blame] | 18 | index_file => $index_file, |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 19 | array => [], |
| Akron | 73ca245 | 2016-11-20 17:09:39 +0100 | [diff] [blame] | 20 | pointers => [] |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 21 | }, $class; |
| 22 | }; |
| 23 | |
| 24 | sub append { |
| 25 | my $self = shift; |
| Akron | ded01ae | 2016-11-23 13:43:54 +0100 | [diff] [blame] | 26 | my (@data) = @_; |
| 27 | if (DEBUG) { |
| 28 | print_log( |
| 29 | 'post', |
| 30 | "Appended " . $self->term . " with " . join(',', @data) |
| 31 | ); |
| 32 | }; |
| 33 | push (@{$self->{array}}, [@data]); |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | sub freq { |
| 37 | return scalar @{$_[0]->{array}}; |
| 38 | }; |
| 39 | |
| 40 | sub term { |
| 41 | return $_[0]->{term}; |
| 42 | }; |
| 43 | |
| Akron | 6e13a06 | 2017-01-13 11:55:28 +0100 | [diff] [blame] | 44 | sub term_id { |
| 45 | return $_[0]->{term_id}; |
| 46 | }; |
| 47 | |
| Akron | 73ca245 | 2016-11-20 17:09:39 +0100 | [diff] [blame] | 48 | sub at { |
| 49 | return $_[0]->{array}->[$_[1]]; |
| 50 | }; |
| 51 | |
| 52 | sub pointer { |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 53 | my $self = shift; |
| Akron | 73ca245 | 2016-11-20 17:09:39 +0100 | [diff] [blame] | 54 | # TODO: Add pointer to pointer list |
| 55 | # so the PostingsList knows, which fragments to lift |
| 56 | # Be aware, this may result in circular structures |
| 57 | Krawfish::Index::PostingPointer->new($self); |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| Akron | ded01ae | 2016-11-23 13:43:54 +0100 | [diff] [blame] | 60 | sub to_string { |
| 61 | my $self = shift; |
| 62 | join(',', map { '[' . $_ . ']' } @{$self->{array}}); |
| 63 | }; |
| 64 | |
| 65 | |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 66 | 1; |
| 67 | |
| 68 | __END__ |
| 69 | |
| Akron | 5f52153 | 2016-10-21 19:30:23 +0200 | [diff] [blame] | 70 | |
| 71 | |
| 72 | |