unique data

P

Peter Meier

Hi,

I'd like to use the gem "rubytree" to store some data in a tree.
But this requires a unique name for each node.

Does anybody has some advice, how to generate such a unique id?
Could be a random, but unique number, ...

Thanks
Peter
 
M

MonkeeSage

Peter said:
Does anybody has some advice, how to generate such a unique id?
Could be a random, but unique number, ...

Hi Peter,

How about a type-4 UUID?

class UUID
@@range = %{0123456789abcdef}.split(//)
@@indices = [7,11,15,19]
def self.new
uuid=[]
32.times { |i|
uuid << @@range[rand(16)]
uuid << '-' if @@indices.include?(i)
}
uuid.join
end
end
puts UUID.new

Mabye just using the object_id of the node itself or the object you're
inserting into the node would work?

Regards,
Jordan
 
R

Robert Klemme

Peter said:
Hi,

I'd like to use the gem "rubytree" to store some data in a tree.
But this requires a unique name for each node.

Does anybody has some advice, how to generate such a unique id?
Could be a random, but unique number, ...

Why not use a counter?

robert
 
M

MonkeeSage

Robert said:
Why not use a counter?

Doh! Curse you rubyists for always thinking of easy ways to do things!
I'm going to fire up perl5 and write some code, just to spite you! ;)

Regards,
Jordan
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,213
Messages
2,571,106
Members
47,699
Latest member
lovelybaghel

Latest Threads

Top