java - HashTable without Collections Library -
i trying create basic file system. not allowed use collections
library. file system stores 2 types of data files
, directories
. types file
, directory
both subclasses of abstract type entry
.
my design far
my hash function take name of entry
, convert each char in name integer , sum them 1 value. next mod value size of array determine placed
protected static int hashfunction(string entryname) { char[] = entryname.tochararray(); int sum = 0; // convert string integer value (char b : a) { sum += (int) b; } int hashvalue = sum % hashtablekey; return hashvalue; }
what having trouble designing hash table. currently, once hash function computes value, store name of entry
(entryname
) in array relative hashvaue
. store actual objects in array of same size hold these objects. storage of these objects have same index respective names in array hold object's names.
*objects can either file or directory
| "obj1" | none | "obj3" | none | none | none | "obj2" | none | | obj1 | none | obj3 | none | none | none | obj2 | none |
not sure if way implement file system using hashtable. reason why chose hashtable due o(1) ups. has big space requirement. way implemented it. if there better way implement file system please let me know! open ideas!!
i don't think should have other array, either store actual object in first array, because entity know it's name sanity checking when selecting element easy.
although see design flaw, unless misunderstood something, prone errors when 2 files have same hash code here entirelly possible because can store many objects many keys there in hashtable.
how solved instead of having array of strings , entities should have array of linkedlist (well, implementation of linked list since cannot use collections) , store entities in lists, make performance reliant on how hash function is,but lessen required space also, although not much. that's how java's hash map works more or less.
just on personal note, don't depend on 2 arrays having same objects on same index, it's error prone.
Comments
Post a Comment