Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashtbl.remove/clear never shrink the internal bucket array #5555

Closed
vicuna opened this issue Mar 26, 2012 · 5 comments
Closed

Hashtbl.remove/clear never shrink the internal bucket array #5555

vicuna opened this issue Mar 26, 2012 · 5 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Mar 26, 2012

Original bug ID: 5555
Reporter: Christoph Bauer
Assigned to: @lefessan
Status: closed (set by @xavierleroy on 2015-12-11T18:04:51Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 3.12.1
Fixed in version: 4.00.0+dev
Category: standard library
Monitored by: @rixed mehdi "Julien Signoles" @yakobowski

Bug description

The internal bucket array of an hashtable grows in Hashtbl.add/replace,
but neither Hashtbl.remove nor Hashtbl.clear shrink the table.

@vicuna
Copy link
Author

vicuna commented May 15, 2012

Comment author: @lefessan

A new function Hashtbl.reset has been added to resize the bucket table to its initial size.

@vicuna
Copy link
Author

vicuna commented May 15, 2012

Comment author: @rixed

It's not quite resizing. So the user is supposed to track the size of the hash and reset it when judged appropriate ?

@vicuna
Copy link
Author

vicuna commented May 15, 2012

Comment author: @lefessan

True, it's not resizing, it is clearing and resetting to the initial size. Users should only use it if they need to recover some space, otherwise, they probably want to keep the current size and just clear all entries.

@vicuna
Copy link
Author

vicuna commented May 15, 2012

Comment author: @rixed

Oh, reading your comment then the actual diff I realize that reset also clears the hashtbl.

I then respectfully disagree with closing this ticket, then.
That's very nice to have both clear and reset behavior (but I'd favor to add an optional boolean argument to clear that would additionnally shrinks the hash size).

It seams to me that the initial concern was that when using long lived hashtables which sizes may vary in great proportion then the overall size of all hashtable growth continuously, which hurts memory and thus performances.

I understand that shrinking dynamically a hash is a tedious topic (one must avoid to continuously grow/shrink), though.

@vicuna
Copy link
Author

vicuna commented Jun 6, 2012

Comment author: Christoph Bauer

I would have expect, that Hashtbl.remove calls resize like add, if the table is less than 3/8 (or 1/4) full.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants