NAME

Meta::Ds::Hash - data structure that represents a hash table.

COPYRIGHT

Copyright (C) 2001, 2002 Mark Veltzer; All rights reserved.

LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.

DETAILS

MANIFEST: Hash.pm
PROJECT: meta
VERSION: 0.41

SYNOPSIS

package foo;
use Meta::Ds::Hash qw();
use Error qw(:try);
my($hash)=Meta::Ds::Hash->new();
$hash->insert("mark","veltzer");
$hash->insert("linus","torvals");
$hash->remove("mark");
if($hash->has("mark")) {
	throw Meta::Error::Simple("error");
}

DESCRIPTION

This is a library to let you create a hash like data structure. "Why should I have such a data strcuture ?" you rightly ask... Perl already supports hashes as built in structures, but these dont have a size method (for one...)... This encapsulates hash as a object and is much better (built over the builtin implementation). This is a value less hash (no values for the inserted ones...), so it effectivly acts as a set.

FUNCTIONS

new($)
insert($$$)
put($$$)
overwrite($$$)
remove($$)
size($)
has($$)
hasnt($$)
check_has($$)
check_hasnt($$)
get($$)
load($$)
save($$)
clear($)
filter($$)
foreach($$)
add_hash($$)
remove_hash($$)
add_key_prefix($$)
internal_hash($)
TEST($)

FUNCTION DOCUMENTATION

new($)

Gives you a new Hash object.

insert($$$)

Inserts an element into the hash. If the element already exists this DOES NOTHING. This receives: 0. Hash object. 1. Element to insert. 2. Value to insert. This returns whether the value was actually inserted.

put($$$)

This will put a new element in the hash. If the element is already a part of the hash it will throw an exception. Arguments: 0. Hash object. 1. Element to insert. 2. Value to insert.

overwrite($$$)

This will overwrite an element in the hash. If the element is not already in the hash it will throw an exception. Arguments: 0. Hash object. 1. Element to insert. 2. Value to insert.

remove($$)

Remove an element from the hash. This receives: 0. Hash object. 1. Element to remove. The method will throw an exception if the element does not exist in the current hash.

size($)

Return the number of elements in the hash. This receives: 0. Hash object.

has($$)

Returns a boolean value according to whether the specified element is in the hash. This receives: 0. Hash object. 1. Element to check for.

hasnt($$)

Returns a boolean value according to whether the specified element is not in the hash. This receives: 0. Hash object. 1. Element to check for.

check_has($$)

This method will throw an exception if the key passed to it does not exist in the hash. The method receives: 0. Hash object. 1. Element to check for.

check_hasnt($$)

This method does the exact opposite of check_has.

get($$)

This returns a certain element from the hash.

load($$)

This will read a hash from a file assuming that file has an entry for the hash as two string separated by a space on each line until the end of the file.

save($$)

This will write a hash table as in the read method. See that methods documentation for details.

clear($)

This method will clear all elements in the hash. It is fast.

filter($$)

This method receives a hash table and some code reference. The method will return a hash which has all the elements in the original hash for which the code did not throw any exceptions.

foreach($$)

This method will iterate over all elements of the hash and will run a user given function on everyone of them. The function should receive two inputs: a key and a value. The function can do just about anything you like.

add_hash($$)

This method adds a hash to the current one by iterating over it's elements and adding them one by one.

remove_hash($$)

This method removes a give hash from the current one. It does so by iterating over the given hashs elements and removing them one by one from the current hash. This method receives: 0. Hash object. 1. Hash object which contains elements to be removed.

add_key_prefix($$)

This method will return a new hash which will be exactly like the original except every key will be prefixed by the prefix you give.

internal_hash($)

This method will give you the internal hash that this data structure uses. Be careful and use it read only or you risk rendering this data structure unusable.

TEST($)

Test suite for this module. This test suite is can be called directly to test very basic functionality of this class or by a higher level test code to test the entire functionality of a class library this class is provided with. Currently this test only creates a small hash and dumps it.

SUPER CLASSES

None.

BUGS

None.

AUTHOR

Name: Mark Veltzer
Email: mailto:veltzer@cpan.org
WWW: http://www.veltzer.org
CPAN id: VELTZER

HISTORY

0.00 MV initial code brought in
0.01 MV bring databases on line
0.02 MV handle architectures better
0.03 MV get the databases to work
0.04 MV ok. This is for real
0.05 MV ok - this time I realy mean it
0.06 MV make quality checks on perl code
0.07 MV more perl checks
0.08 MV make Meta::Utils::Opts object oriented
0.09 MV check that all uses have qw
0.10 MV fix todo items look in pod documentation
0.11 MV add enumerated types to options
0.12 MV more on tests/more checks to perl
0.13 MV change new methods to have prototypes
0.14 MV correct die usage
0.15 MV finish Simul documentation
0.16 MV perl code quality
0.17 MV more perl quality
0.18 MV more perl quality
0.19 MV perl documentation
0.20 MV more perl quality
0.21 MV perl qulity code
0.22 MV more perl code quality
0.23 MV revision change
0.24 MV languages.pl test online
0.25 MV PDMT/SWIG support
0.26 MV Pdmt stuff
0.27 MV perl packaging
0.28 MV md5 project
0.29 MV database
0.30 MV perl module versions in files
0.31 MV movies and small fixes
0.32 MV more thumbnail stuff
0.33 MV thumbnail user interface
0.34 MV more thumbnail issues
0.35 MV website construction
0.36 MV web site automation
0.37 MV SEE ALSO section fix
0.38 MV move tests to modules
0.39 MV weblog issues
0.40 MV teachers project
0.41 MV md5 issues

SEE ALSO

Meta::Error::NoSuchElement(3), Meta::Error::Simple(3), Meta::IO::File(3), strict(3)

TODO

-Add many more routines: 1. add/subtract a hash. 2. get a list from a hash. 3. get a set from a hash. 4. get a hash from a list. 5. get a hash from a set. 6. insert an element and make sure that he wasnt there. 7. remove an element and make sure that he was there.

-add a limitation on the types of objects going into the hash (they must be inheritors from some kind of object).

-make option for hash to be strict (that insert twice will yell).

-make all methods here return the hash object so more ops could be performed.