Professional Web Applications Themes

Concatenating Hash's - Ruby

On Mon, 30 Jun 2003 00:08:39 +0000, Anders Borch wrote: > Simon Strandgaard wrote: >> >> Sorry no profiling.. maybe someone else can add it ? > > require 'profile' > > ? Yes I know 'profile.rb' ... I wasn't aware of Hash#update, so I started to write a function for filling up a hash with random stuff. Then I discovered Hash#update.. and felt very ackward :-) I don't know how to benchmark hash concatenation ? I assume Hash#update is the most optimal one can get. -- Simon Strandgaard...

  1. #1

    Default Re: Concatenating Hash's

    On Mon, 30 Jun 2003 00:08:39 +0000, Anders Borch wrote:
    > Simon Strandgaard wrote:
    >>
    >> Sorry no profiling.. maybe someone else can add it ?
    >
    > require 'profile'
    >
    > ?
    Yes I know 'profile.rb' ... I wasn't aware of Hash#update, so I started
    to write a function for filling up a hash with random stuff.
    Then I discovered Hash#update.. and felt very ackward :-)

    I don't know how to benchmark hash concatenation ?

    I assume Hash#update is the most optimal one can get.

    --
    Simon Strandgaard
    Simon Strandgaard Guest

  2. #2

    Default Re: Concatenating Hash's

    Simon Strandgaard wrote:
    > On Wed, 25 Jun 2003 01:32:27 +0900, David Landrith wrote:
    >
    >
    >>What is the fastest way to concatenate two hash tables?
    >
    >
    >
    > Have you tried Hash#update ?
    >
    >
    > But you ask about the fastest way... hmm.
    >
    >
    >
    >>expand -t2 b.rb
    >
    > class String
    > def String.rand(size=15)
    > s = String.new
    > size.times do |i|
    > s << (Kernel.rand(93)+33) # ascii range
    > end
    > s
    > end
    > end
    >
    > class Hash
    > def Hash.rand(elements, width)
    > h = Hash.new
    > elements.times do
    > key = String.rand(width)
    > h[key] = Kernel.rand(899)+100
    > end
    > h
    > end
    > end
    >
    > h1 = Hash.rand(100, 5)
    > h2 = Hash.rand(100, 5)
    > puts "h1=#{h1.size} h2=#{h2.size}"
    > h1.update(h2)
    > puts "h1=#{h1.size} h2=#{h2.size}"
    >
    >
    >>ruby b.rb
    >
    > h1=100 h2=100
    > h1=200 h2=100
    >
    >
    >
    > Sorry no profiling.. maybe someone else can add it ?
    require 'profile'

    ?
    > --
    > Simon Strandgaard
    >

    --
    dc -e
    4dd*od3*dddn1-89danrn10-dan3+ann6*dan*2*an13dn1+dn2-dn3+5*ddan2/9+an13nap

    Anders Borch Guest

  3. #3

    Default Re: Concatenating Hash's

    Hi,

    In message "Re: Concatenating Hash's"
    on 03/07/02, "Simon Strandgaard" <0bz63fz3m1qt3001sneakemail.com> writes:

    |How is Hash#update different from Hash#merge! are one just an aliases ?

    Aliases.

    matz.

    Yukihiro Matsumoto Guest

Similar Threads

  1. concatenating results in a new var
    By fu-meng in forum Coldfusion - Getting Started
    Replies: 3
    Last Post: May 27th, 06:45 PM
  2. Sort a hash based on values in the hash stored as arrays of hashes
    By Tore Aursand in forum PERL Miscellaneous
    Replies: 3
    Last Post: September 16th, 10:14 AM
  3. Another reference question (hash of hash references)
    By Tim Musson in forum PERL Beginners
    Replies: 2
    Last Post: August 8th, 01:11 PM
  4. Concatenating
    By TK in forum Microsoft Access
    Replies: 1
    Last Post: July 28th, 02:51 PM
  5. Concatenating A Double
    By Ron in forum ASP.NET General
    Replies: 2
    Last Post: July 2nd, 10:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139