[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re2: [MacPerl] BigInt sluggishness.



At 12:18 -0500 2000.12.03, bert wrote:
>David Steffen wrote about using binary operators and such...which i thought
>about but know little about. I figured converting back to base 10 would
>produce an even larger number...so that technique was out, i'm sure there
>are other ways of using them in binary form though.

Here's another way.  vec() is kinda confusing, but fun.  :)

#!perl -wl
use strict;
my %class = (
	a => '000000111000000000000000111000000000000000000000',
	b => '000000000000000111000000000000001110000000000000',
	c => '000000000001000000000000011100000000000000000000',
);

my %tested;

my $length = 48 - 1;  # 0..n
for my $c (keys %class) {
	my $read = '';
	my @schedule = split //, $class{$c};
	for (0 .. $length) {
		vec($read, $_, 1) = 1 if $schedule[$_];
	}
	$class{$c} = $read;  # overwrite
}

for my $c1 (sort keys %class) {
	for my $c2 (sort keys %class) {
		next if $c1 eq $c2;
		next if exists $tested{$c1, $c2};
		if (my @conflicts = test($c1, $c2)) {
			print "Classes $c1 and $c2 conflict in times ",
				join(', ', @conflicts), ".";
		} else {
			print "Classes $c1 and $c2 do not conflict.";
		}
	}
}

sub test {
	my($c1, $c2) = @_;
	my @conflicts;
	for (0 .. $length) {
		push @conflicts, $_ if
			vec($class{$c1}, $_, 1) && vec($class{$c2}, $_, 1);
	}

	# Don't run the same comparison again
	$tested{$c2, $c1} = 1;

	return @conflicts;
}

__END__

Classes a and b do not conflict.
Classes a and c conflict in times 25, 26.
Classes b and c do not conflict.

-- 
Chris Nandor                      pudge@pobox.com    http://pudge.net/
Open Source Development Network    pudge@osdn.com     http://osdn.com/

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org