Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to make many generic objects
    text
    copied!<p><strong>Background</strong></p> <p>For class, I made a linear-chaining hash table. It stores an array of linked lists, and whenever get or put is called, the key is hashed and modulo'd by the array size. The get or put is then called on the resulting linked list (which I also implemented).</p> <p>I have an <code>ST</code> (symbol table) interface. It is much like <code>Map</code>, but some of <code>Map</code>'s required operations were too confusing for me to implement. Implementing this interface I have implementations of a linked list, red-black tree, linear-probing hash table, and the linear-chaining hash table.</p> <p>I would like to make a something similar to a linear-chaining hash table that accepts an arbitrary delegate symbol table type. For example, initializing it with the red-black tree type would make a table of red-black trees, and the get and put functions would delegate to those red-black trees.</p> <p>I recognize that my implementations are almost certainly slower than the library-provided ones, and that I would be better off to use those in real code. I am just trying to experiment and learn.</p> <p><strong>Question</strong></p> <p>What is the best way to supply a type to my hash table so that the hash table will consist of a table of that type, and calls will delegate to those symbol tables?</p> <p>I can't use generics because I can't initialize those, and I need to initialize on construction and on re-sizing.</p> <p>I thought about providing a blank symbol table of the desired type to start, and then using the <code>copy</code> method on that, but it seems like there should be a better way. Is there?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload