From: Rutger Nijlunsing <rutger@nospam.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Josef Weidendorfer <Josef.Weidendorfer@gmx.de>,
Rutger Nijlunsing <git@wingding.demon.nl>,
git@vger.kernel.org
Subject: Re: Object hash (was: Re: [ANNOUNCE] git-rev-size: calculate sizes of repository)
Date: Sun, 20 Aug 2006 19:40:54 +0200 [thread overview]
Message-ID: <20060820174054.GB21362@nospam.com> (raw)
In-Reply-To: <Pine.LNX.4.63.0608201846110.28360@wbgn013.biozentrum.uni-wuerzburg.de>
> Second, since you call hash_put() once per object, hash->nr cannot grow
> too big, because grow_hash() doubles hash->alloc. And I call grow_hash()
> once the hash map is half-full; Somebody once told me that would be the
> optimal growing strategy.
Optimal growing mainly means to be O(n) (amortized) after n
inserts. That translates to at least _doubling_ (factor 2 or more) the
capacity once you're too full.
Assume doubling at a percentage full. Assume realloc(s) takes O(s)
(where s = number of bytes). Assume we start with 1 element.
We realloc() then when we've got 1 element, then at 2, 4, 8 etc. The
size of the realloc() at each point will also be 1, 2, 4, 8
etc. However, this cost of O(s) can be amortized over the number of
elements. So the work done _per insert_ is still a constant (amortized
again).
Ascilly:
x x x x x x x x x x ... (each insert)
R R R ... (each realloc)
1 2 0 4 0 0 0 8 0 0 ... (cost of those realloc())
This has also to do with the infinite series of the sum(k>0) of 2^-k
being a constant.
--
Rutger Nijlunsing ---------------------------------- eludias ed dse.nl
never attribute to a conspiracy which can be explained by incompetence
----------------------------------------------------------------------
next prev parent reply other threads:[~2006-08-20 17:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-20 10:54 [ANNOUNCE] git-rev-size: calculate sizes of repository Rutger Nijlunsing
2006-08-20 13:20 ` Johannes Schindelin
2006-08-20 15:24 ` Rutger Nijlunsing
2006-08-20 16:09 ` Johannes Schindelin
2006-08-20 16:37 ` Object hash (was: Re: [ANNOUNCE] git-rev-size: calculate sizes of repository) Josef Weidendorfer
2006-08-20 16:51 ` Johannes Schindelin
2006-08-20 17:40 ` Rutger Nijlunsing [this message]
2006-08-20 18:41 ` Josef Weidendorfer
2006-08-20 18:47 ` Johannes Schindelin
2006-08-20 17:24 ` [ANNOUNCE] git-rev-size: calculate sizes of repository Rutger Nijlunsing
2006-08-20 18:44 ` Johannes Schindelin
2006-08-20 21:38 ` Junio C Hamano
2006-08-20 23:36 ` Johannes Schindelin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060820174054.GB21362@nospam.com \
--to=rutger@nospam.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=Josef.Weidendorfer@gmx.de \
--cc=git@vger.kernel.org \
--cc=git@wingding.demon.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).