how does sort work on hash

Discussion in 'Ruby' started by hemant kumar, Aug 19, 2006.

  1. hemant kumar

    hemant kumar Guest

    I am just a little curious about how exactly sort workes on hashes.

    for example:
    a = {:foo => 10,:bar => 5,:duh => 20}

    a.sort {|x,y| y[1] <=> x[1]}


    now how exactly the above line works.the block is passed two elements at a
    time, as array? If yes, how sort treates the next two elements?

    what algorithm this sort is based on? Is it inplace sorting? or only sort!
    does inplace sorting?

    May be the question is not so much about hashes.
     
    hemant kumar, Aug 19, 2006
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Navin
    Replies:
    1
    Views:
    1,127
    Ken Schaefer
    Sep 9, 2003
  2. rp
    Replies:
    1
    Views:
    861
    red floyd
    Nov 10, 2011
  3. Mmcolli00 Mom
    Replies:
    5
    Views:
    271
    Mmcolli00 Mom
    Jan 12, 2009
  4. Tore Aursand
    Replies:
    3
    Views:
    766
    Anno Siegel
    Sep 16, 2003
  5. Malik Yousef

    Sort Hash o Hash accordint to two keys

    Malik Yousef, May 6, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    425
    Uri Guttman
    May 7, 2004
  6. Malik Yousef

    Sort Hash o Hash accordint to two keys

    Malik Yousef, May 6, 2004, in forum: Perl Misc
    Replies:
    0
    Views:
    197
    Malik Yousef
    May 6, 2004
  7. Replies:
    11
    Views:
    344
    Eric Schwartz
    Oct 10, 2005
  8. Replies:
    1
    Views:
    203
    Xicheng Jia
    Sep 15, 2006
Loading...