English 中文(简体)
页: 1 多毛 has
原标题:Ruby performance: Multi-key hashes

Suppose I 有一些研究表,q(w, x, y, z),其中各种关键图与不同数值的组合;即:q(0, 0, 0, 0) = a,q(0, 0, 1) = b,q(15, 16, 23,“b”) = c

如何以效率在鲁比拉执行这一结构? 关键因素将动态产生,而且通常会加强。 我可以想到三种不同的关键方法:

  1. Use a string as the key: q["a, b, c, d"] = 0
  2. Use a single array as the key: q[["a", "b", "c", "d"]] = 0
  3. Use a hash of hashes: q["a"]["b"]["c"]["d"] = 0

我目前使用方法2,但比我所希望的要慢一点。 这些关键组合是动态产生的——如果我使用一只透镜的散射,那么扼杀的步伐就会加快? 我是否应该首先用 has头开始? 这种方法是否会在记忆中占据更多的空间?

最佳回答

我选择像你第1号这样的东西:形成一个单一体,然后作为你的地图钥匙。 然而,确保贵方的代谢 has岩对于各种价值观组合来说是适当的独一无二的。 在这种情况下,你只得建立简单地说明,需要一个单一的地图。

总的来说,你想要把钥匙描绘成尽可能不易变。 (关键突变可冲上表)。 有时,鲁比拉的迷信是 mu,但仍然是一个值得追求的目标。

问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签