File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Top Open diff view settings Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -145,6 +145,13 @@ class HashMap {
145145 // Optional: both `keys` has the same content except that the new one doesn't have empty spaces from deletions
146146 this . keys = newMap . keys ;
147147 }
148+
149+ /**
150+ *
151+ */
152+ getLoadFactor ( ) {
153+ return this . size / this . buckets . length ;
154+ }
148155}
149156
150157// Usage:
@@ -185,12 +192,18 @@ hashMap.set('undefined', 'string type');
185192
186193assert . equal ( hashMap . get ( undefined ) , 'undefined type' ) ;
187194assert . equal ( hashMap . get ( 'undefined' ) , 'string type' ) ;
195+ assert . equal ( hashMap . size , 5 ) ;
188196
189- // internal structure
197+ // ----
198+ // Internal structure tests
199+ // ----
190200console . log ( hashMap . collisions ) ;
191201console . log ( hashMap . buckets ) ;
192202
203+ assert . equal ( hashMap . getLoadFactor ( ) , 5 ) ;
204+
193205// rehash
194- hashMap . rehash ( ) ;
206+ hashMap . rehash ( 1000 ) ;
195207console . log ( hashMap . collisions ) ;
196208console . log ( hashMap . buckets ) ;
209+ assert . equal ( hashMap . getLoadFactor ( ) , 5 / 1000 ) ;
You can’t perform that action at this time.
0 commit comments