IterateMap emits a map iteration calling cb for each element in the map where: i is a pointer to the sequential index of the element starting from 0 of type idxTy. k is a pointer to the element key. v is a pointer to the element value.
(s *S, mapPtr *codegen.Value, idxTy semantic.Type, cb func(i, k, v *codegen.Value))
| 492 | // k is a pointer to the element key. |
| 493 | // v is a pointer to the element value. |
| 494 | func (c *C) IterateMap(s *S, mapPtr *codegen.Value, idxTy semantic.Type, cb func(i, k, v *codegen.Value)) { |
| 495 | capacity := mapPtr.Index(0, MapCapacity).Load() |
| 496 | elPtr := mapPtr.Index(0, MapElements).Load() |
| 497 | iTy := c.T.Target(idxTy) |
| 498 | i := s.LocalInit("i", s.Scalar(0).Cast(iTy)) |
| 499 | s.ForN(capacity.Cast(iTy), func(s *S, it *codegen.Value) *codegen.Value { |
| 500 | used := elPtr.Index(it, "used").Load() |
| 501 | s.If(s.Equal(used, s.Scalar(mapElementFull)), func(s *S) { |
| 502 | k := elPtr.Index(it, "k") |
| 503 | v := elPtr.Index(it, "v") |
| 504 | cb(i, k, v) |
| 505 | i.Store(s.Add(i.Load(), s.Scalar(1).Cast(iTy))) |
| 506 | }) |
| 507 | return nil |
| 508 | }) |
| 509 | } |