blog.2grafic.com

Disseny i Programacio

01 marzo
1Comment

Estructuras de datos: tabla hash

*Noticia extraida de mi amigo C鳡r Tard᧵ila.

http://www.design-nation.net/es/archivos/cat_flashactionscript.php

Una tabla hash es una especie de colecció® ¤e listas enlazadas. Nos permite guardar pares clave-valor, y luego recuperar esos datos utilizando la clave.

Encontrará³ una definició® ­ejor aquí

Y mi implementació® ¦lt;a href=”http://www.design-nation.net/en/archives/hashMap.mxp”>aquí

Para testearlo puedes utilizar algo como esto:

import net.designnation.structs.*

var a: HashMap= new HashMap( );

// Setitem
//
key= “4″;
trace( “Agrego “+ key );
a.setItem( key, new Object( key ) );
trace( “Contenidos del HashMap: “+ a.toString( ) );

key= “21″;
trace( “Agrego “+ key );
a.setItem( key, [ "a1", "a2" ] );
trace( “Contenidos del HashMap: “+ a.toString( ) );

key= “5″;
trace( “Agrego “+ key );
a.setItem( key, new Object( key ) );
trace( “Contenidos del HashMap: “+ a.toString( ) );

key= “8″;
trace( “Agrego “+ key );
a.setItem( key, new Object( key ) );
trace( “Contenidos del HashMap: “+ a.toString( ) );

key= “81″;
trace( “Agrego “+ key );
a.setItem( key, new Object( key ) );
trace( “Contenidos del HashMap: “+ a.toString( ) );

key= “8″;
trace( “Agrego “+ key );
a.setItem( key, new Object( key ) );

trace( “Contenidos del HashMap: “+ a.toString( ) );
// GetItem
//
key= “8″;
trace( “Tomo el valor de “+ key );
trace( a.getItem( key ).toString( ) );
// Count
//
trace( “Tamañ¯º “+ a.count( ) );

// Remove
//
key= “4″;
trace( “Elimino “+ key );
a.remove( key );
trace( “Contenidos del HashMap: “+ a.toString( ) );
trace( “Tamañ¯º “+ a.count( ) );

key= “4″;
trace( “Elimino “+ key );
a.remove( key );
trace( “Contenidos del HashMap: “+ a.toString( ) );
trace( “Tamañ¯º “+ a.count( ) );

 
Comments are closed.