# $Id: SparseMap.pm,v 1.1 2003/06/04 00:27:53 marka Exp $
#
# Copyright (c) 2001 Japan Network Information Center. All rights reserved.
#
# By using this file, you agree to the terms and conditions set forth bellow.
#
# LICENSE TERMS AND CONDITIONS
#
# The following License Terms and Conditions apply, unless a different
# license is obtained from Japan Network Information Center ("JPNIC"),
# a Japanese association, Kokusai-Kougyou-Kanda Bldg 6F, 2-3-4 Uchi-Kanda,
# Chiyoda-ku, Tokyo 101-0047, Japan.
#
# 1. Use, Modification and Redistribution (including distribution of any
# under this License Terms and Conditions.
#
# 2. Redistribution of source code must retain the copyright notices as they
# appear in each source code file, this License Terms and Conditions.
#
# 3. Redistribution in binary form must reproduce the Copyright Notice,
# materials provided with the distribution. For the purposes of binary
# distribution the "Copyright Notice" refers to the following language:
# "Copyright (c) 2000-2002 Japan Network Information Center. All rights reserved."
#
# 4. The name of JPNIC may not be used to endorse or promote products
# derived from this Software without specific prior written approval of
# JPNIC.
#
# 5. Disclaimer/Limitation of Liability: THIS SOFTWARE IS PROVIDED BY JPNIC
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JPNIC BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
package SparseMap;
use strict;
use Carp;
my $debug = 0;
sub new {
# common options are:
# BITS => [8, 7, 6], # 3-level map, 2nd level bits=7, 3rd = 6.
# MAX => 0x110000 # actually, max + 1.
my $class = shift;
my $self = {@_};
croak "BITS is not an array reference"
}
sub add1 {
my $idx;
my $lv;
unless defined $r->[$idx];
$r = $r->[$idx];
}
}
sub fix {
my $self = shift;
my @tmp;
my @zero;
$self->collapse_tree();
$self->fill_default();
}
sub indices {
my $self = shift;
my $v = shift;
my @idx;
$v = $v >> $bit;
}
@idx;
}
sub get {
my $self = shift;
my $v = shift;
}
}
sub indirectmap {
my $self = shift;
my @indirect = ();
my $offset;
my $chunksz;
# indirect map
} else {
# direct map
$offset = 0;
$chunksz = 1;
}
croak "mapsize inconsistent ", scalar(@$mapref),
foreach my $m (@$mapref) {
my $idx;
}
}
}
}
@indirect;
}
sub cprog_imap {
my $self = shift;
my %opt = @_;
my $prog;
my $i;
my $max = 0;
if ($max < 256) {
$idtype = 'char';
$idcol = 8;
$idwid = 3;
} elsif ($max < 65536) {
$idtype = 'short';
$idcol = 8;
$idwid = 5;
} else {
$idtype = 'long';
$idcol = 4;
$idwid = 10;
}
$prog = "static const unsigned $idtype ${name}_imap[] = {\n";
$i = 0;
foreach my $v (@indirect) {
if ($i % $idcol == 0) {
$prog .= "\t";
}
$prog .= sprintf "%${idwid}d, ", $v;
$i++;
}
$prog .= "\n};\n";
$prog;
}
sub cprog {
my $self = shift;
}
sub stat {
my $self = shift;
my $i;
my $total = 0;
my @lines;
push @lines, "level $i: $nmaps maps (size $mapsz) ";
push @lines, "\n";
}
push @lines, "level $i: $ndmaps dmaps";
my $r = $maps[$i]->[0];
if (ref($r) eq 'ARRAY') {
}
push @lines, "\n";
join '', @lines;
}
sub collapse_tree {
my $self = shift;
my @tmp;
}
sub _collapse_tree_rec {
my $found;
return $r unless defined $r;
} else {
for (my $i = 0; $i < @$r; $i++) {
}
}
unless ($found) {
$found = $r;
}
return $found;
}
sub fill_default {
my $self = shift;
my @zeros;
}
}
sub _fill_default_rec {
for (my $i = 0; $i < @$r; $i++) {
if (defined($r->[$i])) {
} else {
}
}
}
sub create_imap {
my @map;
\@map;
}
sub find_imap {
my $i;
for ($i = 0; $i < @$el; $i++) {
}
}
undef;
}
sub collect_maps {
my $self = shift;
my @maps;
@maps;
}
sub _collect_maps_rec {
return unless defined $r;
return if $ref == $r;
}
}
}
1;
use strict;
use vars qw(@ISA);
use Carp;
#use SparseMap;
sub new {
my $class = shift;
}
sub add {
my $self = shift;
}
sub create_dmap {
my $self = shift;
\$s;
}
sub add_to_dmap {
}
sub find_dmap {
}
return undef;
}
sub cprog_dmap {
my $self = shift;
my %opt = @_;
my $prog;
$prog = <<"END";
END
my $i = 0;
$prog .= "\t{{\n";
foreach my $v (unpack 'C*', $$bm) {
if ($i % 16 == 0) {
$prog .= "\t";
}
$prog .= sprintf "%3d,", $v;
$i++;
}
$prog .= "\n\t}},\n";
}
$prog .= "};\n";
$prog;
}
1;
use strict;
use vars qw(@ISA);
use Carp;
#use SparseMap;
sub new {
my $class = shift;
}
sub add {
my $self = shift;
while (@_ > 0) {
my $n = shift;
my $val = shift;
}
}
sub create_dmap {
my $self = shift;
\@tbl;
}
sub add_to_dmap {
}
sub find_dmap {
if (@$map == @$r) {
my $i;
for ($i = 0; $i < @$map; $i++) {
last if $map->[$i] != $r->[$i];
}
}
}
return undef;
}
sub cprog_dmap {
my $self = shift;
my %opt = @_;
my $prog;
my $i;
foreach my $a (@table) {
foreach my $v (@$a) {
}
}
} else {
if ($absmax < 256) {
$idtype = "${u}char";
} elsif ($absmax < 65536) {
$idtype = "${u}short";
} else {
$idtype = "${u}long";
}
}
$prog = <<"END";
END
foreach my $a (@table) {
my $i = 0;
my $col = 0;
$prog .= "\t{{\n\t";
foreach my $v (@$a) {
my $s = sprintf "%${idwid}d, ", $v;
$col += length($s);
if ($col > 70) {
$prog .= "\n\t";
$col = length($s);
}
$prog .= $s;
}
$prog .= "\n\t}},\n";
}
$prog .= "};\n";
$prog;
}
sub decimalwidth {
my $n = shift;
my $neg = 0;
my $w;
if ($n < 0) {
$neg = 1;
$n = -$n;
}
if ($n < 100) {
$w = 2;
} elsif ($n < 10000) {
$w = 4;
} elsif ($n < 1000000) {
$w = 6;
} elsif ($n < 100000000) {
$w = 8;
} else {
$w = 10;
}
$w + $neg;
}
1;