Gene;
Asi como puedo ordenar un array, bidimensional, puedo ordenar un Hash por su Valor?
gracias
PROCEDURE Main()
loca hashVar:= Hash( "a", "Zaragosa", ;
"b", "Klein" , ;
"c", "Romero" , ;
"d", "Gonzalez", ;
"e", "Baranda" )
HEval( hashVar, {|key,val| wqout({key,val}) })
? "Ordena?"
ASort( hb_HValues( hashVar ) )
HEval( hashVar, {|key,val| wqout({key,val}) }) // No ordena
? "Ordena?"
hashVar := ASort( hb_HValues( hashVar ) )
HEval( hashVar, {|key,val| wqout({key,val}) }) // Da error de argumento en el hash
local hashVar:= Hash( "a", "Zaragosa", ;
"b", "Klein" , ;
"c", "Romero" , ;
"d", "Gonzalez", ;
"e", "Baranda" )
local aValues := ASort( hb_HValues( hashVar ) )
aEval( aValues, {|val| wqout( val ) })
:bKeyDown := {|nK| if( nK==VK_SPACE, ( oQry:LoadQuery(), ;
if( HHasKey( hSelec, oQry:id_player ), ( HDel( hSelec, oQry:id_player ) ), ;
( HSet( hSelec, oQry:id_player, oQry:ApeyNom ), oBrw:GoDown() ) ), ;
if( Len(hSelec) >= 1, aO[_BtOk]:Enable(), aO[_BtOk]:Disable() ) ), ) }
aKeysValues := {
{ k1, v1 },;
{ k2, v2 },;
...
}
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"
PROCEDURE Main()
loca hashVar:= Hash( "a", "Zaragosa", ;
"b", "Klein" , ;
"c", "Romero" , ;
"d", "Gonzalez", ;
"e", "Baranda" )
HEval( hashVar, {|key,val| wqout({key,val}) })
? "Ordena?"
ASort( hb_HValues( hashVar ) )
HEval( hashVar, {|key,val| wqout({key,val}) }) // No ordena
? "Ordena?"
hashVar := ASort( hb_HValues( hashVar ) )
HEval( hashVar, {|key,val| wqout({key,val}) }) // Da error de argumento en el hash
┌────────────────────────────────────────────────────────────────────────────┐
?FiveWin for xHarbour 19.09 - Sep. 2019 xHarbour development power │▄
?(c) FiveTech 1993-2019 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘?
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀?
Compiling...
xHarbour 1.2.3 Intl. (SimpLex) (Build 20190613)
Copyright 1999-2018, http://www.xharbour.org http://www.harbour-project.org/
Compiling 'leandro3.prg' and generating preprocessed output to 'leandro3.ppo'...
Generating C source output to 'leandro3.c'...
Done.
Lines 20, Functions/Procedures 1, pCodes 69
Embarcadero C++ 7.30 for Win32 Copyright (c) 1993-2017 Embarcadero Technologies, Inc.
leandro3.c:
Turbo Incremental Link 6.80 Copyright (c) 1997-2017 Embarcadero Technologies, Inc.
Error: Unresolved external '_HB_FUN_HB_HVALUES' referenced from C:\FWH1909\SAMPLES\LEANDRO3.OBJ
Error: Unable to perform link
* Linking errors *
Recuerda que además de la función hb_HValues( hashVar ) está hb_HKeys( hashVar ), construir un aKeysValues es fácil y que ASort admite un codeblock para ordenar:
ASORT(aKeysValues ,,, { |x, y| x[2] < y[2] }
ASORT( aArti,,, { |x,y| x["i_articu"] < y["i_articu"] } )
function SortHash()
local hHash := Hash( "a", "Zaragosa", ;
"b", "Klein" , ;
"c", "Romero" , ;
"d", "Gonzalez", ;
"e", "Baranda" )
local aPairs, hSort
XBROWSER hHash TITLE "ORIGINAL HASH"
aPairs := {}
HEval( hHash, { | k, v, i | AAdd( aPairs, { k, v } ) } )
ASort( aPairs, nil, nil, { |x,y| x[ 2 ] < y[ 2 ] } )
hSort := {=>}
AEval( aPairs, { |a| HB_HSet( hSort, a[ 1 ], a[ 2 ] ) } )
XBROWSER hSort TITLE "SORTED HASH"
return nil
#include "Fivewin.ch"
function main()
local hHash := Hash( "a", "Zaragosa", ;
"b", "Klein" , ;
"c", "Romero" , ;
"d", "Gonzalez", ;
"e", "Baranda" )
local aPairs, hSort
XBROWSER hHash TITLE "ORIGINAL HASH"
aPairs := {}
HEval( hHash, { | k, v, i | AAdd( aPairs, { k, v } ) } )
ASort( aPairs, nil, nil, { |x,y| x[ 2 ] < y[ 2 ] } )
hSort := {=>}
AEval( aPairs, { |a| HSet( hSort, a[ 1 ], a[ 2 ] ) } )
XBROWSER hSort TITLE "SORTED HASH"
return nil
hHash := hash( "Z", "AA", "A", "ZZ" )
XBROWSER hHash
Return to FiveWin para Harbour/xHarbour
Users browsing this forum: Google [Bot] and 52 guests