🔅 Search & Size

search( item ) {

let key = this.computeHash( item )

return this.table[key] === item

} size() {

let counter = 0;

for( let i=0, len = this.table.length; i < len; i++) {

if( this.table[i] ) { counter++ }

}

return counter;

}

❗️The technique which I am using to find out size is very time consuming. This is one way but the better one will be to use a counter for size. Just increment that counter whenever we put an item in Hash table and decrement it when we delete an item. Just return that counter in the size function so that we do not have to iterate over whole Hash Table very time we call it ( Some geek pointed this on reddit thread… thank you) and in next post I will implement this.

Then why are you still using it here ?

I am still using this because you can use this piece of code for a lot of other things i.e you can use this to traverse over whole Hash Table and implement a function ( may be by some reason you want every value to be in a lowercase or uppercase) over each item which will help you do a lot of other things when you are practicing this. So, this code is just to show that this is one way to do this but as I mentioned that this is not one of the best way to this sort of work. Use pointers instead.