go deep copy map
func deepCopyJSON(src map[string]interface{}, dest map[string]interface{}) error {
if src == nil {
return errors.New("src is nil. You cannot read from a nil map")
}
if dest == nil {
return errors.New("dest is nil. You cannot insert to a nil map")
}
jsonStr, err := json.Marshal(src)
if err != nil {
return err
}
err = json.Unmarshal(jsonStr, &dest)
if err != nil {
return err
}
return nil
}
------------------------
How to copy a map to another map?
package mainimport ("fmt")func main() { map1 := map[string]int{ "x":1, "y":2, } map2 := map[string]int{} /* Copy Content from Map1 to Map2*/ for index,element := range map1{ map2[index] = element } for index,element := range map2{ fmt.Println(index,"=>",element) }} |
x => 1
y => 2
C:\golang\codes>
go deep copy map的更多相关文章
- [Algo] 132. Deep Copy Undirected Graph
Make a deep copy of an undirected graph, there could be cycles in the original graph. Assumptions Th ...
- [Algo] 131. Deep Copy Linked List With Random Pointer
Each of the nodes in the linked list has another pointer pointing to a random node in the list or nu ...
- C# Bitmap deep copy
今天在研究一个关于 Bitmap deep copy 的问题, 经过一系列的查询,在StackOverFlow上面找到了答案,遂记录下来: public static Bitmap DeepCopyB ...
- shallow copy 和 deep copy 的示例
本文属原创,转载请注明出处:http://www.cnblogs.com/robinjava77/p/5481874.html (Robin) Student package base; impo ...
- python deep copy and shallow copy
Python中对于对象的赋值都是引用,而不是拷贝对象(Assignment statements in Python do not copy objects, they create bindings ...
- Deep Copy cv::StereoBM 深度拷贝
在使用OpenCV的三维立体重建的库时,一个重要的步骤就是生成左右视图的差异图Disparity,而控制生成disparity的参数的类是cv::StereoBM,我们有时候需要拷贝一份cv::Ste ...
- shallow copy & deep copy
1.深复制与浅复制的概念 ->浅复制(shallow copy)概念 在SDK Guides中(搜索copy),官方给出的浅复制概念为: Copying compound objects, ...
- 【C#】Deep copy of objects
If you learned C++ carefully, you must have known something about the copy of object. For example, I ...
- NumPy学习(索引和切片,合并,分割,copy与deep copy)
NumPy学习(索引和切片,合并,分割,copy与deep copy) 目录 索引和切片 合并 分割 copy与deep copy 索引和切片 通过索引和切片可以访问以及修改数组元素的值 一维数组 程 ...
随机推荐
- 【leetcode算法-中等】3. 无重复字符的最长字串
[题目描述] 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度. 示例 1: 输入: "abcabcbb"输出: 3 解释: 因为无重复字符的最长子串是 " ...
- html5 外链式实现加减乘除
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- JSON文件转为Excel
前言 今天在帮老师做年终党统的时候,发现管理平台上没有将正在发展的同志的信息导出功能,只能一个一个点击进去查看,操作起来步骤很多很麻烦,所以我就想到了"扒"一下这个网页,扒下来发现 ...
- AlgorithmMap Dev Log
Log 2019.08.29 ------------------------------------------------------------------------------------- ...
- Robot 安装
安装一个测试环境的 下载python27 升级pip E:\Python27\python -m pip install --upgrade pip 安装robotramework E:\Python ...
- golang使用注意事项
1.可以给类型取别名,但是该类型和别名是两个不同的类型: type myInt int 2.go支持可变参数:args... 0个或多个参数:func sum(args... int) sum int ...
- 关于arm 的字节对齐
一.什么是字节对齐,为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这 ...
- 关于UBOOT,LINUX内核编译,根文件系统的15个小问题
(1)内核默认运行地址和加载地址在哪里设置? 由 arch/arm/kernel/vmlinux.lds.S 生成的 arch/armkernel/vmlinux.lds决定 (2)从FLASH什 ...
- MySQL的explain语句分析
+----+-------------+-------+------------+------+---------------+-----+---------+------+------+------ ...
- Linux中 ls -l 命令显示结果中的每一列的含义
图片转载自:https://blog.csdn.net/zhuoya_/article/details/77418413 简单解释下: 1.第一列颜色框:文件类型列,这里简单描述几种常见类型,d表示目 ...