Tie::Hash::Cannabinol

2001-06-06 Thread Cross David - dcross


Once an idea gets into my head, the only way to shake it off is to go away
and write it :)

Dave...

package Tie::Hash::Cannabinol;

use strict;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require Tie::Hash;

@ISA = qw(Exporter Tie::StdHash);
@EXPORT = qw();
@EXPORT_OK =();

$VERSION = '0.01';

sub FETCH {
  my $self = shift;

  my @keys = keys %$self;

  return $self-{$keys[rand $#keys]};
}

sub EXISTS {
  return rand  0.5;
}

1;
__END__

=head1 NAME

Tie::Hash::Cannabinol - A hash on hash!

=head1 SYNOPSIS

  use Tie::Hash::Cannabinol;
  my %h;

  tie %h, 'Tie::Hash::Cannabinol';

=head1 DESCRIPTION

The idea of writing a tied hash called T::H::C was just too good to ignore.

You can store values in this hash just as you would a normal hash, but
when you ask for a value back, you get any random value from the hash.

The Cexists function isn't really to be trusted either :)

=head1 AUTHOR

Dave Cross [EMAIL PROTECTED]

=head1 SEE ALSO

perl(1).

perltie(1).

=cut


The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged. If the reader 
of this message is not the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  
If you have received this communication in error, please 
re-send this communication to the sender and delete the 
original message or any copy of it from your computer
system.



Re: Tie::Hash::Cannabinol

2001-06-06 Thread Simon Wistow

Cross David - dcross wrote:
 
   return $self-{$keys[rand $#keys]};

Shouldn't this just gradually start to forget more and more things using
Tie::Hash::Decay?

And then start consuming your resources when it gets the munchies?

Or chuck a whitey and start spewing out spurious data everywhere or ...

I'll get me coat.


-- 
simon wistowwireless systems coder
i think, i said i think this is our fault.



RE: Tie::Hash::Cannabinol

2001-06-06 Thread Richard Clyne

I always thought that a data structure that mimicked a bus queue would
be useful.

If you request more items than are in the queue (e.g. lots of empty
seats) the queue returns the items in order.  If you request less items
than are in the queue (Bus almost full) the largest items push through
and are selected.

Richard

 -Original Message-
 From: Simon Wistow [SMTP:[EMAIL PROTECTED]]
 Sent: 06 June 2001 11:11
 To:   [EMAIL PROTECTED]
 Subject:  Re: Tie::Hash::Cannabinol
 
 Cross David - dcross wrote:
  
return $self-{$keys[rand $#keys]};
 
 Shouldn't this just gradually start to forget more and more things
 using
 Tie::Hash::Decay?
 
 And then start consuming your resources when it gets the munchies?
 
 Or chuck a whitey and start spewing out spurious data everywhere or
 ...
 
 I'll get me coat.
 
 
 -- 
 simon wistowwireless systems coder
 i think, i said i think this is our fault.



Re: Tie::Hash::Cannabinol

2001-06-06 Thread Robin Szemeti

On Wed, 06 Jun 2001, Simon Wistow wrote:
 Cross David - dcross wrote:
  
return $self-{$keys[rand $#keys]};
 
 Shouldn't this just gradually start to forget more and more things using
 Tie::Hash::Decay?

no .. if the program is left alone for a while it begins attaching really
carefully constructed little data structures to each element of the hash,
and then filling little arrays of data structures with really small
patterns ...

-- 
Robin Szemeti   

Redpoint Consulting Limited
Real Solutions For A Virtual World 



Re: Tie::Hash::Cannabinol

2001-06-06 Thread Greg McCarroll

* Richard Clyne ([EMAIL PROTECTED]) wrote:
 I always thought that a data structure that mimicked a bus queue would
 be useful.
 
 If you request more items than are in the queue (e.g. lots of empty
 seats) the queue returns the items in order.  If you request less items
 than are in the queue (Bus almost full) the largest items push through
 and are selected.

Fun!

the following should do what you want, although i'm not sure if freezing
non-references is fair on them and i'm sure the sort condition syntax
can be shortened by the perl golfers on the list ...

package BusQueue;

use strict;
use Storable qw(freeze);

sub new {
my $class = shift;
my $self  = [];
return bless $self, $class;
}

sub insert {
my $self = shift;
push(@$self, @_);
}

sub remove {
my $self = shift;
my ($num) = @_;
@$self = sort {
my $sa;
my $sb;
if (ref($a)) {
$sa = length(freeze($a));
} else {
$sa = length(freeze(\$a));
}
if (ref($b)) {
$sb = length(freeze($b));
} else {
$sb = length(freeze(\$b));
}
$sb = $sa;
} @$self;
return splice @$self, 0, $num;
}

1;


-- 
Greg McCarrollhttp://217.34.97.146/~gem/



Re: Tie::Hash::Cannabinol

2001-06-06 Thread Paul Makepeace

On Wed, Jun 06, 2001 at 05:10:43AM -0500, Richard Clyne wrote:
 If you request more items than are in the queue (e.g. lots of empty
 seats) the queue returns the items in order.  If you request less items
 than are in the queue (Bus almost full) the largest items push through
 and are selected.

package BusStop;

sub FETCH  {
rand  .99 ? (
$self-{$keys[rand @keys]},
$self-{$keys[rand @keys]},
$self-{$keys[rand @keys]}) : undef;
}

Paul

-- 
Always the first steps