1

Topic: When linear search faster hash map

This here discussion the Author: c-smile Date: 05.10 07:47  on article writing on a subject. The case is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. Do not walk children to Africa to walk use std:: map not to destination.

2

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep [/url]. Therefore the Whip and to it is necessary to read with care - though guys and sensible, but  it is a little obsolete if not to consider the device of the modern processor (everyones , a prediction of passages) it is possible to run easily that the algorithm with the worst  suddenly soils algorithm from the good. Well and generally it is necessary to estimate cost of operations - it can suddenly appear that at an insertion on a small array with shift to save orderliness and binary search, soil trees only so.

3

Re: When linear search faster hash map

Hello, c-smile, you wrote: #if ENTRIES> 4... #if ENTRIES> 5... #if ENTRIES> 6... #if ENTRIES> 7... #if ENTRIES> 8... #if ENTRIES> 9... #endif #endif #endif #endif #endif #endif the Beaver, exhale! On a subject, without comments.

4

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. And if to it to compare, it will be even faster: switch (*str ++) {case ' p ': switch (*str ++) {case ' o ': if (length == 4 && *str ++ == ' r ' && *str ++ == ' t ') {...} break; case ' u ': if (length == 9 && *str ++ == ' b ' && *str ++ == ' l ' && *str ++ == ' i ' && *str ++ == ' c ' && *str ++ == ' K ' && *str ++ == ' e ' && *str ++ == ' y ') {...} break;} break;} But there is more to come, after all it is possible to compare not on byte, and at once on 4, for example.

5

Re: When linear search faster hash map

Hello, c-smile, you wrote: If it is fair, I would look narrowly at your test more attentively. 1. For example, transmission of a line on value guards. FormatterType t2e (std:: string s) {...} 2. In containers, std:: map / std:: unordered_map you store objects std:: string, at that time when in function if_t2e comparing goes with wrapper usage slice. 3. Further, + still std:: string that case when it is necessary to be especially attentive, therefore still it is necessary to look at small volumes as the compiler works with lines (what there optimization), it is quite possible that different compilers yield different result. 4. Various implementations std:: hash / std:: equal_to / std:: less for std:: string can yield different result. 5. It is possible to try to store const char* instead of std:: string, probably too shows other result. ...

6

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. In one and a half time (3.44 against 2.13) it "as a bull a sheep"? "Well excuse..." (Vovochka) Also we note, only at 9 records the linear search is already worse . And what further? CS> And over O (log N) - generally continuous violation. Already on pair tens percent. No, here it is clear that std:: map it is normal more slowly std:: unordered_map (if not too expensively to calculate ), but your example just __ that the linear search by default here has been selected. Because any  here by the nature of things also it is well scaled, and changeover by the linear search will be typical premature optimization with all consequences. If this place becomes narrow and there will be a warranty  amounts of key strings - then it is possible to reduce before the linear search. If at least one condition is not fulfilled - the sunset is manually cancelled. And if really fast search - that here is necessary as it to do - to look, for example, in Kamailio: #define _acce_ 0x65636361/* "acce" */#define _allo_ 0x6f6c6c61/* "allo" */#define _auth_ 0x68747561/* "auth" */#define _oriz_ 0x7a69726f/* "oriz" */#define _atio_ 0x6f697461/* "atio" */#define _call_ 0x6c6c6163/* "call" */#define __ id2_ 0x2064692d/* "-id" */#define __ id1_ 0x3a64692d/* "-id:" */[...] #define FIRST_QUATERNIONS \case _via1_: via1_CASE; \case _from_: from_CASE; \case _to12_: to12_CASE; \case _cseq_: cseq_CASE; \case _call_: call_CASE; \case _cont_: cont_CASE; \case _rout_: rout_CASE; \case _max __: max_CASE; \well and so on - the line is cut in the standard portions on 4 bytes, translated to the lower register (SIP titles - case-insensitive) and then the compiler task - to select the correct variant to spread out case (normally it builds something like a tree). Yes, it is very rigid target optimization. But there it is justified. CS> do not walk children to Africa to walk use std:: map not to destination. You did not show, on what amount of values std:: map is more effective than the linear search. It is already ugly. And VS-only code too now somehow "not so".

7

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> do not walk children to Africa to walk use std:: map not to destination. Game in spillikins in comparison with optimization of the critical code by time through , ,  and ..

8

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. So after all anybody also did not promise that O (1) ALWAYS will be faster O (log N), and O (log N) ALWAYS faster O (N). Because all these estimations set only asymptotics of dependence of runtime from the size of input sequence, but are not exact dependence. They allow to say only that there is such size of input sequence over which O (1) starts to benefit at O (log N), and O (log N) at O (N). And here what will be this size, depends already from...

9

Re: When linear search faster hash map

Hello, MTD, you wrote: MTD> Hello, c-smile, you wrote: CS>> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep [/url]. MTD> Therefore the Whip and to it is necessary to read with care - though guys and sensible, but  it is a little obsolete if not to consider the device of the modern processor (everyones , a prediction of passages) it is possible to run easily that the algorithm with the worst  suddenly soils algorithm from the good. The asymptotics describes behavior at aspiration of a variable to something. In application to complexities of algorithms character of behavior is considered at variable magnification, or aspiration to infinity. Besides, O (f (n)) is an upper estimation on determination which only specifies that there is a constant and such n0 that growth of complexity of algorithm at n> = n0 will correspond to some model to within these constants. That is, the asymptotics is not intended for scribing of the lower estimations on small n. And the Whip - it is not clear. He does not state the reverse.

10

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> This here discussion the Author: c-smile Date: 05.10 07:47 induced  on article writing on a subject. CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. CS> do not walk children to Africa to walk use std:: map not to destination. Couple of years faced a similar story back. Looked, as different data structures for storage of subscriptions of agents depending on an amount of these subscriptions behave. It appeared that if subscriptions of all one-two ten storage of subscriptions in std:: vector and simple linear search on it works most effectively. If the amount of subscriptions is in region from pair tens to pair hundreds works std:: map more effectively. And here from 200 + subscriptions - it appears the most effective std:: unordered_map.

11

Re: When linear search faster hash map

Hello, samius, you wrote: S> That is, the asymptotics is not intended for scribing of the lower estimations on small n. Speech not only about small n. S> And a whip - it is not clear. Thus that the Whip did not consider, as algorithms are fulfilled on the modern iron, such theory in vacuum. The nobility it is necessary, but each time it is necessary to think, and blindly to trust in  S> It does not state the reverse. For an estimation of speed of algorithms it is offered to use it  is not always true. For example, at a binary tree and the arranged array the search asymptotics is identical - a logarithm. Whether it means, what they are equally effective? No, after all the tree can be spread on storage because of it there will be constant misses in  and the arranged array appears in times more effectively. It is considered at the Whip? No, here about that and speech.

12

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> This here discussion the Author: c-smile Date: 05.10 07:47 induced  on article writing on a subject. You, unfortunately, did not understand that that discussion at all productivity, and about quality of the code to you even  the code hinted about it CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation.  are good that any decision to thrust in a top is possible, and inconvenient digits simply not to publish CS> do not walk children to Africa to walk use std:: map not to destination. Itself understood, what told? (At me for you the bad news: assignment  to be the associative container, that is to store keys and values and to search on keys you though for outputs can distinctly formulate? Here sorting by a vial too in a top sometimes quits, but outputs from this should still to be able be made

13

Re: When linear search faster hash map

Hello, MTD, you wrote: S>> And the Whip - it is not clear. MTD> thus that the Whip did not consider, as algorithms are fulfilled on the modern iron, such theory in vacuum. The nobility it is necessary, but each time it would be necessary to think, and blindly to trust in the Island I each time told "it is necessary to measure", instead of to "think"." To think "it it is necessary, but not this key. And"  on the modern iron "it is specificity not only the Whip. I  now looked at Kormena, Siena, Sedzhvika - is not mentioned anywhere - at least was not present either in a table of contents, or in the index. Therefore it is necessary to suppose that to them in pair mandatory to read" Computer achitecture: a quantitative approach "or analog. Still you for some reason spread stray logical communication" algorithms, complexity-> the Whip ". A whip - the base and historical basis, but now it to use as the absolute already rather late. S>> He does not state the reverse. MTD> for an estimation of speed of algorithms it is offered to use it  is not always true. For example, at a binary tree and the arranged array the search asymptotics is identical - a logarithm. Whether it means, what they are equally effective? No, after all the tree can be spread on storage because of it there will be constant misses in  and the arranged array appears in times more effectively. It is considered at the Whip? No, here about that and speech. The real world should be considered always. Somewhere the algorithm in 100 times faster on RAM, but in 2 times is more gluttonous on memory size will be braked because of  a swap. Somewhere very effective it becomes normal sorting suddenly more slowly a vial of that comparing in 1000 times is more expensive than an exchange. You reading to the Whip for some reason look only at outputs, instead of to the analysis carried out by it. And after all to what it learns is to analyze from bases. And at all thus do not know anybody, except the Whip... Simply frighten of it.

14

Re: When linear search faster hash map

Hello, netch80, you wrote: N> you reading to the Whip for some reason look only at outputs, instead of to the analysis carried out by it. And after all to what it learns is to analyze from bases. And at all thus do not know anybody, except the Whip... To Telepathists greetings! N> simply frighten of it. The hat from a foil rescues from voices in a head and returns sincere health.

15

Re: When linear search faster hash map

Hello, MTD, you wrote: MTD> Hello, samius, you wrote: S>> That is, the asymptotics is not intended for scribing of the lower estimations on small n. MTD> Speech not only about small n. But  about the lower estimations? S>> and the Whip - it is not clear. MTD> thus that the Whip did not consider, as algorithms are fulfilled on the modern iron, such theory in vacuum. The nobility it is necessary, but each time it is necessary to think, and blindly to trust in O.Tak i on the modern iron cost of performance of a step of algorithm it is nonnegative. I do not understand that changed in this plan since an appearance of the book. As the whip did not suggest to trust blindly in O.Ne I know, from which phrase you drew such output. S>> he does not state the reverse. MTD> for an estimation of speed of algorithms it is offered to use it  is not always true. It not so. The asymptotics is offered to be used for the forecast of growth of cost of algorithm at magnification n. Thus that M and x0 are unknown, as about it and specified the Whip. MTD> for example, at a binary tree and the arranged array the search asymptotics is identical - a logarithm. Whether it means, what they are equally effective? No, after all the tree can be spread on storage because of it there will be constant misses in  and the arranged array appears in times more effectively. It is considered at the Whip? No, here about that and speech. Speech here it is equal that you made an incorrect estimation and the forecast. Incorrectly selected M and x0 at an estimation of speed of operation of algorithms on a tree in the conditions of constant misses. There are no bases to state on identical efficiency of algorithms with one asymptotics, without knowing constants. About it the Whip also wrote.

16

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> This here discussion the Author: c-smile Date: 05.10 07:47 induced  on article writing on a subject. CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. And what wild delight causes in them that the sorted array can faster be processed in times than the same but not sorted. Without std:: sort (data, data + arraySize); the code runs in 11.54 seconds. With the sorted data, the code runs in 1.93 seconds.

17

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> This here discussion the Author: c-smile Date: 05.10 07:47 induced  on article writing on a subject. CS> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. Well, it not news for a long time already. "" the processor, the size of caches, character of the data, their deal in storage and other like trifles are capable to defame the most theoretically-best algorithms.

18

Re: When linear search faster hash map

Hello, MTD, you wrote: MTD> Hello, c-smile, you wrote: CS>> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep [/url]. MTD> Therefore the Whip and to it is necessary suddenly read <...> it can to appear that at an insertion on a small array with shift to save orderliness and binary search, soil trees only so. 1) So therefore structures like B-tree also invented... 2) At that Whip which was read once by me, it has been directly written that with very good asymptotics you would not invent what fine recursive algorithm, is normal since some size and less, it is necessary to switch to something fast on the small data

19

Re: When linear search faster hash map

Hello, so5team, you wrote: S> Couple of years faced a similar story back. Looked, as different data structures for storage of subscriptions of agents depending on an amount of these subscriptions behave. It appeared that if subscriptions of all one-two ten storage of subscriptions in std:: vector and simple linear search on it works most effectively. If the amount of subscriptions is in region from pair tens to pair hundreds works std:: map more effectively. And here from 200 + subscriptions - it appears the most effective std:: unordered_map. It was possible to make B-tree on 10-20 subscriptions to a node, - would combine advantages of different lines of thought...

20

Re: When linear search faster hash map

Hello, MTD, you wrote: MTD> And if still with it to compare it will be even faster: I about it too wrote. Approximately that that generates it perfect hash (gperf).

21

Re: When linear search faster hash map

Hello, Engler, you wrote: E> Hello, c-smile, you wrote: E> If it is fair, I would look narrowly at your test more attentively. E> 1. For example, transmission of a line on value guards. E> E> FormatterType t2e (std:: string s) {...} E> it is not important. For this signature is used in all compared functions. E> 2. In containers, std:: map / std:: unordered_map you store objects std:: string, E> at that time when in function if_t2e comparing goes with wrapper usage slice. And it and? E> 3. Further, + still std:: string that case when it is necessary to be especially attentive, E> therefore still it is necessary to look at small volumes as the compiler works with lines (what there optimization), E> it is quite possible that different compilers yield different result. E> 4. Various implementations std:: hash / std:: equal_to / std:: less for std:: string can yield different result. E> 5. It is possible to try to store const char* instead of std:: string, probably too shows other result. I about it also speak. It is necessary to look at a real situation, instead of it is stupid to take std:: map for search in a dial-up.

22

Re: When linear search faster hash map

Hello, c-smile, you wrote: CS> I about it too wrote. Approximately that that generates it perfect hash (gperf). Well it generates strongly another (how much I remember), besides, at what in a context of arguing it (same the hash function generator)?

23

Re: When linear search faster hash map

Hello, MTD, you wrote: MTD> Hello, c-smile, you wrote: CS>> I about it too wrote. Approximately that that generates it perfect hash (gperf). MTD> Well it generates strongly another (how much I remember), besides, at what in a context of arguing it (same the hash function generator)? gperf generates function in which strcmp it is used exactly once (i.e. the full pass of a line). As the discriminator the length of a line and one or several values characters is used. About the same FSA as you wrote as I understood.

24

Re: When linear search faster hash map

Hello, rg45, you wrote: R> Hello, c-smile, you wrote: CS>> the case Is resulted when O (N) lookup covers O (1) as a bull a sheep. And over O (log N) - generally continuous violation. R> so after all anybody also did not promise that O (1) ALWAYS will be faster O (log N), and O (log N) ALWAYS faster O (N). Because all these estimations set only asymptotics of dependence of runtime from the size of input sequence, but are not exact dependence. They allow to say only that there is such size of input sequence over which O (1) starts to benefit at O (log N), and O (log N) at O (N). And here what will be this size, depends already from... Well actually about it and speech. It is all about this here the citation: the Expert:" If it is caused not once it will be obvious that std:: map more effectively since tree initialization will happen only once. And it by the way not the theory - I use in practice such approach (only with string_view, instead of string as a key for map)."

25

Re: When linear search faster hash map

Hello, uzhas, you wrote: U> Hello, c-smile, you wrote: CS>> This here discussion the Author: c-smile Date: 05.10 07:47 induced  on article writing on a subject. U> you, unfortunately, did not understand, what that discussion at all productivity, and about quality of code U> to you even  the code hinted about it That there is such "a quality of the code" in a considered context?