@@ -327,10 +327,6 @@ fn map_free_nop(_ voidptr) {
327
327
}
328
328
329
329
fn new_map (key_bytes int , value_bytes int , hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn) map {
330
- return new_map_2 (key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
331
- }
332
-
333
- fn new_map_2 (key_bytes int , value_bytes int , hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn) map {
334
330
metasize := int (sizeof (u32 ) * (init_capicity + extra_metas_inc))
335
331
// for now assume anything bigger than a pointer is a string
336
332
has_string_keys := key_bytes > sizeof (voidptr )
@@ -353,18 +349,13 @@ fn new_map_2(key_bytes int, value_bytes int, hash_fn MapHashFn, key_eq_fn MapEqF
353
349
}
354
350
355
351
fn new_map_init (hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int , key_bytes int , value_bytes int , keys voidptr , values voidptr ) map {
356
- return new_map_init_2 (hash_fn, key_eq_fn, clone_fn, free_fn, n, key_bytes, value_bytes,
357
- keys, values)
358
- }
359
-
360
- fn new_map_init_2 (hash_fn MapHashFn, key_eq_fn MapEqFn, clone_fn MapCloneFn, free_fn MapFreeFn, n int , key_bytes int , value_bytes int , keys voidptr , values voidptr ) map {
361
- mut out := new_map_2 (key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
352
+ mut out := new_map (key_bytes, value_bytes, hash_fn, key_eq_fn, clone_fn, free_fn)
362
353
// TODO pre-allocate n slots
363
354
mut pkey := & byte (keys)
364
355
mut pval := & byte (values)
365
356
for _ in 0 .. n {
366
357
unsafe {
367
- out.set_1 (pkey, pval)
358
+ out.set (pkey, pval)
368
359
pkey = pkey + key_bytes
369
360
pval = pval + value_bytes
370
361
}
@@ -445,14 +436,10 @@ fn (mut m map) ensure_extra_metas(probe_count u32) {
445
436
}
446
437
}
447
438
448
- fn (mut m map) set (key voidptr , value voidptr ) {
449
- m.set_1 (key, value)
450
- }
451
-
452
439
// Insert new element to the map. The element is inserted if its key is
453
440
// not equivalent to the key of any other element already in the container.
454
441
// If the key already exists, its value is changed to the value of the new element.
455
- fn (mut m map) set_1 (key voidptr , value voidptr ) {
442
+ fn (mut m map) set (key voidptr , value voidptr ) {
456
443
load_factor := f32 (m.len << 1 ) / f32 (m.even_index)
457
444
if load_factor > max_load_factor {
458
445
m.expand ()
@@ -546,14 +533,10 @@ fn (mut m map) cached_rehash(old_cap u32) {
546
533
unsafe { free (old_metas) }
547
534
}
548
535
549
- fn (mut m map) get_and_set (key voidptr , zero voidptr ) voidptr {
550
- return m.get_and_set_1 (key, zero)
551
- }
552
-
553
536
// This method is used for assignment operators. If the argument-key
554
537
// does not exist in the map, it's added to the map along with the zero/default value.
555
538
// If the key exists, its respective value is returned.
556
- fn (mut m map) get_and_set_1 (key voidptr , zero voidptr ) voidptr {
539
+ fn (mut m map) get_and_set (key voidptr , zero voidptr ) voidptr {
557
540
for {
558
541
mut index, mut meta := m.key_to_index (key)
559
542
for {
@@ -572,20 +555,16 @@ fn (mut m map) get_and_set_1(key voidptr, zero voidptr) voidptr {
572
555
}
573
556
}
574
557
// Key not found, insert key with zero-value
575
- m.set_1 (key, zero)
558
+ m.set (key, zero)
576
559
}
577
560
assert false
578
561
return voidptr (0 )
579
562
}
580
563
581
- fn (m &map) get (key voidptr , zero voidptr ) voidptr {
582
- return m.get_1 (key, zero)
583
- }
584
-
585
564
// If `key` matches the key of an element in the container,
586
565
// the method returns a reference to its mapped value.
587
566
// If not, a zero/default value is returned.
588
- fn (m &map) get_1 (key voidptr , zero voidptr ) voidptr {
567
+ fn (m &map) get (key voidptr , zero voidptr ) voidptr {
589
568
mut index, mut meta := m.key_to_index (key)
590
569
for {
591
570
if meta == unsafe { m.metas[index] } {
@@ -605,15 +584,11 @@ fn (m &map) get_1(key voidptr, zero voidptr) voidptr {
605
584
return zero
606
585
}
607
586
608
- fn (m &map) get_check (key voidptr ) voidptr {
609
- return m.get_1_check (key)
610
- }
611
-
612
587
// If `key` matches the key of an element in the container,
613
588
// the method returns a reference to its mapped value.
614
589
// If not, a zero pointer is returned.
615
590
// This is used in `x := m['key'] or { ... }`
616
- fn (m &map) get_1_check (key voidptr ) voidptr {
591
+ fn (m &map) get_check (key voidptr ) voidptr {
617
592
mut index, mut meta := m.key_to_index (key)
618
593
for {
619
594
if meta == unsafe { m.metas[index] } {
@@ -633,12 +608,8 @@ fn (m &map) get_1_check(key voidptr) voidptr {
633
608
return 0
634
609
}
635
610
636
- fn (m &map) exists (key voidptr ) bool {
637
- return m.exists_1 (key)
638
- }
639
-
640
611
// Checks whether a particular key exists in the map.
641
- fn (m &map) exists_1 (key voidptr ) bool {
612
+ fn (m &map) exists (key voidptr ) bool {
642
613
mut index, mut meta := m.key_to_index (key)
643
614
for {
644
615
if meta == unsafe { m.metas[index] } {
@@ -708,12 +679,8 @@ pub fn (mut m map) delete(key voidptr) {
708
679
}
709
680
}
710
681
711
- fn (m &map) keys () array {
712
- return m.keys_1 ()
713
- }
714
-
715
682
// Returns all keys in the map.
716
- fn (m &map) keys_1 () array {
683
+ fn (m &map) keys () array {
717
684
mut keys := __new_array (m.len, 0 , m.key_bytes)
718
685
mut item := unsafe { & byte (keys.data) }
719
686
if m.key_values.deletes == 0 {
0 commit comments