Meta::Ds::Map - a 1-1 map object.


Meta documentation  | view source Contained in the Meta distribution.

Index


NAME

Top

Meta::Ds::Map - a 1-1 map object.

COPYRIGHT

Top

LICENSE

Top

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

Top

	MANIFEST: Map.pm
	PROJECT: meta
	VERSION: 0.02

SYNOPSIS

Top

	package foo;
	use Meta::Ds::Map qw();
	my($object)=Meta::Ds::Map->new();
	my($result)=$object->method();

DESCRIPTION

Top

This data structure is a 1-1 map. This means that you can for instance, store a social id to driver id mapping (since no two people have the same social id or driver id). Trying to insert a value which already exists (in either of the hashes) will cause an exception.

This class is implemented using a pair of Hash structures. This means that querying in each direction (A to B or B to A) is quite efficient.

Removal is also quite efficient (O(1) on both sides).

Size is implemented as size of one of the hashes (they are always the same size).

FUNCTIONS

Top

	BEGIN()
	new($)
	insert($$$)
	has_a($$)
	has_b($$)
	get_a($$)
	get_b($$)
	remove_a($$)
	remove_b($$)
	remove($$$)
	size($)
	clear($)
	foreach($$)
	TEST($)

FUNCTION DOCUMENTATION

Top

BEGIN()

Bootstrap method for this class which creates the accessors for hash_a and hash_b. This means that you can access the actual hashes using get_hash_a and get_hash_b. Just be careful to do it for read only access becuase toying with these without knowing what you are doing may render this class unusable.

new($)

This is a constructor for the Meta::Ds::Map object.

insert($$$)

This inserts an pair into the map object.

has_a($$)

Returns whether the map has the element in side A.

has_b($$)

Returns whether the map has the element in side B.

get_a($$)

This retrieves the pair of element on side A.

get_b($$)

This retrieves the pair of element on side B.

remove_a($$)

This removes a pair according to element on side A.

remove_b($$)

This removes a pair according to element on side B.

remove($$$)

This method removes a pair from the map.

size($)

This method will give you the size of the map.

clear($)

This method will clear the map. It is quick.

foreach($$)

This method will run a piece of code given to it on every pair of elements in the map. The code should be a subroutine which accepts two arguments. The arguments are a and then b.

TEST($)

This is a testing suite for the Meta::Ds::Map module. This test is should be run by a higher level management system at integration or release time or just as a regular routine to check that all is well.

Currently this test creates the object, does some manipulation and dumps it.

SUPER CLASSES

Top

None.

BUGS

Top

None.

AUTHOR

Top

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

HISTORY

Top

	0.00 MV teachers project
	0.01 MV more pdmt stuff
	0.02 MV md5 issues

SEE ALSO

Top

Meta::Class::MethodMaker(3), Meta::Ds::Hash(3), Meta::Error::Simple(3), Meta::Utils::Output(3), strict(3)

TODO

Top

-stop using ordered hashes for this class - it does not make use of them.

-idea: store another hash with all pairs joined by $;. This could be used for fast iteration on all elements.


Meta documentation  | view source Contained in the Meta distribution.