Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #2017
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border1.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail |
|---|---|
| NNTP-Posting-Date | Thu, 04 Sep 2014 17:04:13 -0500 |
| From | Scott Hemphill <hemphill@hemphills.net> |
| Newsgroups | comp.lang.postscript |
| Subject | Re: Sizing a dictionary |
| References | <c4bee501-d466-4f52-af0f-c37c2023703d@googlegroups.com> |
| Reply-To | hemphill@alumni.caltech.edu |
| Date | Thu, 04 Sep 2014 18:04:13 -0400 |
| Message-ID | <m3bnqvdov6.fsf@hemphills.net> (permalink) |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) |
| Cancel-Lock | sha1:jWQQD1ehz4aH2M1il05wr2mc+ro= |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Lines | 40 |
| X-Usenet-Provider | http://www.giganews.com |
| X-Trace | sv3-8eEBIVJQE1TcAfqFBb84dT+TPu7REqAyDPte6JzIfZQyCa/bnaifIthKjm3BJ5o/W1ccqLDlxqpk23P!2LVGopckZXy9wMelo7RIVcKWXi66H2giCq7APkIpRwPXdyYRKaBmzgU= |
| X-Complaints-To | abuse@giganews.com |
| X-DMCA-Notifications | http://www.giganews.com/info/dmca.html |
| X-Abuse-and-DMCA-Info | Please be sure to forward a copy of ALL headers |
| X-Abuse-and-DMCA-Info | Otherwise we will be unable to process your complaint properly |
| X-Postfilter | 1.3.40 |
| X-Original-Bytes | 3537 |
| X-Received-Bytes | 3604 |
| X-Received-Body-CRC | 749334459 |
| Xref | csiph.com comp.lang.postscript:2017 |
Show key headers only | View raw
jdaw1 <jdawiseman@gmail.com> writes:
> At language level ≥2 dictionaries can created with length 0, as they grow automatically. But I always create them to be the correct length, to match the maximum value of currentdict length.
>
> These lengths are sometimes checked with:
>
> /dict {dup 1 add dict dup 3 -1 roll /DictionaryOriginalSize exch put} bind def
>
> /end {currentdict /DictionaryOriginalSize known {DictionaryOriginalSize currentdict length 1 sub lt {TypeOfPagesBeingRendered = DictionaryOriginalSize = currentdict length 1 sub = (###) =} if} if end} bind def
>
>
>
> In https://groups.google.com/forum/#!topic/comp.lang.postscript/hc9-b2W5tY0 luser- -droog wrote:
>> `10 dict` creates a dict with capacity for 10 elements
>> (rule of thumb: double the expected size needed for speedy hash lookups)
>
> The quoted text advising aiming for double size. Oooh: that’s new to me. Please, is there evidence of this? It feels like messy programming, so I’d do it only reluctantly. Is there background that I should read? Please say more.
http://en.wikibooks.org/wiki/Data_Structures/Hash_Tables
When the Apple LaserWriter first came out, I bought the PostScript Red
Book and started figuring out how PostScript Level I was implemented.
In the case of dictionaries, I figured out (modulo my foggy memory) that
if you asked for a dictionary of size smaller than 10, it was promoted
to 10. Also, whatever size you specified, the internal dictionary was
allocated to be 25% bigger than you asked. I vaguely recall that hash
collisions were resolved by linear probing using a step of one location.
Collisions become more frequent as the dictionary fills up (or is
constructed) so a dictionary should never be allowed to become more than
80% full (this is the conventional figure, I don't know the original
source). Note that the 25% premium allows the dictionary to be just 80%
full when you've filled it with the expected number of elements.
See also: Knuth, vol. 3 "Sorting and Searching" section 6.4 Hashing
Also: Google "hash table 80% full" (without the quotes).
Scott
--
Scott Hemphill hemphill@alumni.caltech.edu
"This isn't flying. This is falling, with style." -- Buzz Lightyear
Back to comp.lang.postscript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Sizing a dictionary jdaw1 <jdawiseman@gmail.com> - 2014-09-03 03:57 -0700
Re: Sizing a dictionary Scott Hemphill <hemphill@hemphills.net> - 2014-09-04 18:04 -0400
Re: Sizing a dictionary luser- -droog <mijoryx@yahoo.com> - 2014-09-04 16:59 -0700
Re: Sizing a dictionary jdaw1 <jdawiseman@gmail.com> - 2014-09-06 03:31 -0700
Re: Sizing a dictionary Scott Hemphill <hemphill@hemphills.net> - 2014-09-09 13:35 -0400
Re: Sizing a dictionary luser- -droog <mijoryx@yahoo.com> - 2014-09-13 01:11 -0700
Re: Sizing a dictionary Scott Hemphill <hemphill@hemphills.net> - 2014-09-13 12:04 -0400
csiph-web