Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 10 of 19 for SetMapIndex (0.72 sec)

  1. src/reflect/set_test.go

    	"testing"
    	"unsafe"
    )
    
    func TestImplicitMapConversion(t *testing.T) {
    	// Test implicit conversions in MapIndex and SetMapIndex.
    	{
    		// direct
    		m := make(map[int]int)
    		mv := ValueOf(m)
    		mv.SetMapIndex(ValueOf(1), ValueOf(2))
    		x, ok := m[1]
    		if x != 2 {
    			t.Errorf("#1 after SetMapIndex(1,2): %d, %t (map=%v)", x, ok, m)
    		}
    		if n := mv.MapIndex(ValueOf(1)).Interface().(int); n != 2 {
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Wed Sep 07 13:56:11 UTC 2022
    - 5.7K bytes
    - Viewed (0)
  2. test/fixedbugs/issue48357.go

    // license that can be found in the LICENSE file.
    
    package main
    
    import "reflect"
    
    type T [129]byte
    
    func main() {
    	m := map[string]T{}
    	v := reflect.ValueOf(m)
    	v.SetMapIndex(reflect.ValueOf("a"), reflect.ValueOf(T{}))
    	g = m["a"]
    }
    
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Mon Sep 13 18:38:15 UTC 2021
    - 360 bytes
    - Viewed (0)
  3. test/fixedbugs/issue37716.go

    	c    float64
    }
    
    func main() {
    	k := K{a: 1, b: 2, c: 3}
    
    	// Make a reflect map.
    	m := reflect.MakeMap(reflect.MapOf(reflect.TypeOf(K{}), reflect.TypeOf(true)))
    	m.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(true))
    
    	// The binary must not contain the type map[K]bool anywhere, or reflect.MapOf
    	// will use that type instead of making a new one. So use an equivalent named type.
    	type M map[K]bool
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Mar 10 16:26:59 UTC 2020
    - 872 bytes
    - Viewed (0)
  4. staging/src/k8s.io/apimachinery/pkg/api/apitesting/fuzzer/valuefuzz.go

    			for _, k := range obj.MapKeys() {
    				// map values are not addressable. We need a copy.
    				v := obj.MapIndex(k)
    				copy := reflect.New(v.Type())
    				copy.Elem().Set(v)
    				valueFuzz(copy.Elem())
    				obj.SetMapIndex(k, copy.Elem())
    			}
    			// TODO: set some new value
    		}
    	case reflect.Func: // ignore, we don't have function types in our API
    	default:
    		if !obj.CanSet() {
    			return
    		}
    		switch obj.Kind() {
    Registered: Sat Jun 15 01:39:40 UTC 2024
    - Last Modified: Sat Jun 25 16:23:43 UTC 2022
    - 2.3K bytes
    - Viewed (0)
  5. staging/src/k8s.io/apimachinery/pkg/runtime/converter.go

    			if err := fromUnstructured(val, value, ctx); err != nil {
    				return err
    			}
    		} else {
    			value.Set(reflect.Zero(dt.Elem()))
    		}
    		if st.Key().AssignableTo(dt.Key()) {
    			dv.SetMapIndex(key, value)
    		} else {
    			dv.SetMapIndex(key.Convert(dt.Key()), value)
    		}
    	}
    	return nil
    }
    
    func sliceFromUnstructured(sv, dv reflect.Value, ctx *fromUnstructuredContext) error {
    	st, dt := sv.Type(), dv.Type()
    Registered: Sat Jun 15 01:39:40 UTC 2024
    - Last Modified: Tue Jul 11 16:02:13 UTC 2023
    - 24.9K bytes
    - Viewed (0)
  6. operator/pkg/util/reflect.go

    		v = v.Elem()
    	}
    
    	if v.Type().Kind() != reflect.Map {
    		scope.Debugf("error %v", v.Type().Kind())
    		return fmt.Errorf("insertIntoMap parent type is %T, must be map", parentMap)
    	}
    
    	v.SetMapIndex(kv, vv)
    
    	return nil
    }
    
    // DeleteFromMap deletes an entry with the given key parent, which must be a map.
    func DeleteFromMap(parentMap any, key any) error {
    Registered: Fri Jun 14 15:00:06 UTC 2024
    - Last Modified: Mon Jul 25 19:30:47 UTC 2022
    - 8.6K bytes
    - Viewed (0)
  7. src/reflect/benchmark_test.go

    					for j := tt.keys.Len() - 1; j >= 0; j-- {
    						tt.m.MapIndex(tt.keys.Index(j))
    					}
    				}
    			})
    			b.Run("SetMapIndex", func(b *testing.B) {
    				b.ReportAllocs()
    				for i := 0; i < b.N; i++ {
    					for j := tt.keys.Len() - 1; j >= 0; j-- {
    						tt.m.SetMapIndex(tt.keys.Index(j), tt.value)
    					}
    				}
    			})
    		})
    	}
    }
    
    func BenchmarkMapIterNext(b *testing.B) {
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Sun Nov 19 17:09:03 UTC 2023
    - 8.8K bytes
    - Viewed (0)
  8. test/escape_reflect.go

    	v.SetPointer(x)
    }
    
    func setmapindex(m map[string]string, k, e string) { // ERROR "m does not escape" "leaking param: k$" "leaking param: e$"
    	mv := reflect.ValueOf(m)
    	kv := reflect.ValueOf(k) // ERROR "k escapes to heap"
    	ev := reflect.ValueOf(e) // ERROR "e escapes to heap"
    	mv.SetMapIndex(kv, ev)
    }
    
    // Unfortunate: k doesn't need to escape.
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Fri Sep 08 18:50:24 UTC 2023
    - 13.1K bytes
    - Viewed (0)
  9. staging/src/k8s.io/apimachinery/pkg/api/apitesting/roundtrip/construct.go

    		// recurse to populate the item, preserving the data context
    		fill(dataString, dataInt, t.Elem(), item.Elem(), fillFuncs, filledTypes)
    		// store in the map
    		v.Set(reflect.MakeMap(t))
    		v.SetMapIndex(key, item.Elem())
    
    	case reflect.Struct:
    		for i := 0; i < t.NumField(); i++ {
    			field := t.Field(i)
    
    			if !field.IsExported() {
    				continue
    			}
    
    Registered: Sat Jun 15 01:39:40 UTC 2024
    - Last Modified: Mon Feb 27 19:12:59 UTC 2023
    - 6.5K bytes
    - Viewed (0)
  10. src/go/internal/gccgoimporter/testdata/v1reflect.gox

     func (v <type 1>) SetComplex (x <type -18>);
     func (v <type 1>) SetFloat (x <type -10>);
     func (v <type 1>) SetInt (x <type -4>);
     func (v <type 1>) SetLen (n <type -11>);
     func (v <type 1>) SetMapIndex (key <type 1>, val <type 1>);
     func (v <type 1>) SetUint (x <type -8>);
     func (v <type 1>) SetPointer (x <type 7>);
     func (v <type 1>) SetString (x <type -16>);
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Thu Sep 30 21:33:51 UTC 2021
    - 10.3K bytes
    - Viewed (0)
Back to top