473,406 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Large Dictionaries

Hi all.

I have the need to store a large (10M) number of keys in a hash table,
based on a tuple of (long_integer, integer). The standard python
dictionary works well for small numbers of keys, but starts to
perform badly for me inserting roughly 5M keys:

# keys dictionary metakit (both using psyco)
------ ---------- -------
1M 8.8s 22.2s
2M 24.0s 43.7s
5M 115.3s 105.4s

Has anyone written a fast hash module which is more optimal for
large datasets ?

p.s. Disk-based DBs are out of the question because most
key lookups will result in a miss, and lookup time is
critical for this application.

Cheers,
Chris
May 15 '06
57 10778
In article <ma***************************************@python. org>,
"Tim Peters" <ti********@gmail.com> wrote:
For example, the O(N log N) heapsort is unreasonable compared to the
O(N**2) bubblesort by that reasoning (pre-sorted is actually a bad
case for heapsort, but a good case for bubblesort)? O(N log N)
sorting algorithms helped by pre-existing order are uncommon, unless
they do extra work to detect and exploit pre-existing order.


Shellsort works well with nearly-sorted data. It's basically a smarter
version of bubblesort with much improved efficiency. It's also very
compact to implement.
Jun 8 '06 #51
In article <11********************@j55g2000cwa.googlegroups.c om>,
"Iain King" <ia******@gmail.com> wrote:
Lawrence D'Oliveiro wrote:
In article <44********@nntp0.pdx.net>,
Scott David Daniels <sc***********@acm.org> wrote:
>For example, time timsort (Python's internal sort) on pre-sorted
>data; you'll find it is handled faster than random data.


But isn't that how a reasonable sorting algorithm should behave? Less
work to do if the data is already sorted?


An already sorted list can be pathological for Quicksort, depending on
how you code it.


I did say "reasonable". :)
Jun 8 '06 #52
[Tim Peters]
...
O(N log N) sorting algorithms helped by pre-existing order are
uncommon, unless they do extra work to detect and exploit
pre-existing order.

[Lawrence D'Oliveiro] Shellsort works well with nearly-sorted data. It's basically a smarter
version of bubblesort with much improved efficiency. It's also very
compact to implement.


shellsort is much more a refinement of insertion-sort than of
bubblesort, but is not an O(N log N) algorithm regardlesss. A nice,
succinct summary of what was known about shellsort's behavior as of
Sedgewick's 1996 "Analysis of Shellsort and Related Algorithms" can be
found here:

http://www.inf.fh-flensburg.de/lang/...ll/shellen.htm
Jun 8 '06 #53
Tim Peters wrote:
shellsort is much more a refinement of insertion-sort than of
bubblesort, but is not an O(N log N) algorithm regardlesss.


With a judiciously chosen increment sequence,
the number of comparisons made by shellsort
*is* of the order N log N for practical values of N.
See Figure 8 in
http://sun.iinf.polsl.gliwice.pl/~mciura/shellsort.pdf
Marcin
Jun 9 '06 #54
Marcin Ciura wrote:
Tim Peters wrote:
shellsort is much more a refinement of insertion-sort than of
bubblesort, but is not an O(N log N) algorithm regardlesss.
With a judiciously chosen increment sequence,
the number of comparisons made by shellsort
*is* of the order N log N for practical values of N.
See Figure 8 in
http://sun.iinf.polsl.gliwice.pl/~mciura/shellsort.pdf


That isn't what the reference says. It only covers N up to a few thousand.
Practical values of N need to at least go up into the millions.

Read the summary: Using sequential analysis, the search for optimal increment sequences
for Shellsort was accelerated enough to find them for arrays up to
several thousand elements. .... However, the sequences obtained so far are too short to draw a
reliable conclusion whether an appropriate sequence of increments can
make Shellsort a O(N logN) sorting method on the average. Some
hypotheses may be possible when the sequences are prolonged to sort
arrays of about 10^5 elements.


Jun 9 '06 #55
Duncan Booth wrote:
Marcin Ciura wrote:
See Figure 8 in
http://sun.iinf.polsl.gliwice.pl/~mciura/shellsort.pdf

That isn't what the reference says. It only covers N up to a few thousand.
Practical values of N need to at least go up into the millions.


Please look at the performance graph of Tokuda's increment sequence.
You can see that it scales pretty well at least up to 100 million.
Marcin
Jun 9 '06 #56
Marcin Ciura wrote:
Duncan Booth wrote:
Marcin Ciura wrote:
See Figure 8 in
http://sun.iinf.polsl.gliwice.pl/~mciura/shellsort.pdf

That isn't what the reference says. It only covers N up to a few
thousand. Practical values of N need to at least go up into the
millions.


Please look at the performance graph of Tokuda's increment sequence.
You can see that it scales pretty well at least up to 100 million.


Ah sorry, I misread it. It was sequences with several thousand elements,
which corresponds to N of 100 million.
Jun 9 '06 #57
Thomas Ganss wrote:
Klaas schrieb:
4. Insert your keys in sorted order.

This advice is questionable -
it depends on the at least on the db vendor and probably
sometimes on the sort method, if inserting pre-sorted
values is better.


The article I wrote that you quoted named a specific vendor (berkeley
db) for which my advice is unquestionable and well-known.

-Mike

Jun 12 '06 #58

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: robin | last post by:
I need to do a search through about 50 million records, each of which are less than 100 bytes wide. A database is actually too slow for this, so I thought of optimising the data and putting it all...
8
by: placid | last post by:
Hi all, Just wondering if anyone knows how to pop up the dialog that windows pops up when copying/moving/deleting files from one directory to another, in python ? Cheers
2
by: Gabriel Genellina | last post by:
En Wed, 30 Jul 2008 21:29:39 -0300, <python@bdurham.comescribi�: You could use a different hash algorithm yielding a smaller value (crc32, by example, fits on an integer). At the expense of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.