goversion_maprange_lt_go112.go 590 B

1234567891011121314151617181920212223242526272829
  1. // Copyright (c) 2012-2018 Ugorji Nwoke. All rights reserved.
  2. // Use of this source code is governed by a MIT license found in the LICENSE file.
  3. // +build !go1.12
  4. package codec
  5. import "reflect"
  6. type mapRanger struct {
  7. rv reflect.Value
  8. mks []reflect.Value
  9. j int
  10. }
  11. func (x *mapRanger) Next() bool {
  12. x.j++
  13. return x.j < len(x.mks)
  14. }
  15. func (x *mapRanger) Key() reflect.Value {
  16. return x.mks[x.j]
  17. }
  18. func (x *mapRanger) Value() reflect.Value {
  19. return x.rv.MapIndex(x.mks[x.j])
  20. }
  21. func mapRange(rv reflect.Value) (g *mapRanger) {
  22. return &mapRanger{rv: rv, mks: rv.MapKeys(), j: -1}
  23. }