Questions tagged [shallow-copy]

A shallow copy of an object is a duplicate that may not be fully independent of the original, in the sense that any references / pointers it holds to other objects refer to the same objects that the original's do. Use this tag for questions regarding implementing or using shallow copying methods.

Shallow copying is a process by which an object is duplicated to create a copy that may not be wholly independent of the original. Also known as "field by field" copying, this differs from deep copying with respect to the treatment of references / pointers to other objects: shallow copying copies the references / pointers held by the original, whereas deep copying makes a deep copy of each referenced object, too. Shallow copying is "shallow" in the sense that it copies only the original object itself, not any appearing deeper in its reference graph.

Related tags

Links

394 questions
1
vote
1 answer

Copying rows from multiple delta tables into one via Spark

I have multiple delta lake tables storing images data. Now I want to take specific rows via filter from those tables and put them in another delta table. I do not want to copy the original data just the reference or shallow copy. I am using pyapark…
S.Khan
  • 71
  • 1
  • 7
1
vote
0 answers

Python: anomaly in value of class-variables of different type after changing its value

I was trying to understand the scope of class variables. Value of class variables (string and list type) of parent class, after changing its value using the instance object of its derived class, showed different behavior. When I changed the class…
1
vote
0 answers

why shallow copy is working different for nested list elements and non nested list elements?

Why shallow copy working in different for nested list elements and non nested list elements? I don't understand why it is doing like this. It is doing shallow copy function is working in two different ways: for non-nested list elements working as…
1
vote
1 answer

Potentioal memory leak with spread operator?

I'm just wondering if the following code snippet is a potential memory leak. let arrOfObj = [ { a: 0, b: 0 } ] const copy = [ ...arrOfObj ] copy[0].a = 5; console.log(arrOfObj) // [ { a: 5, b: 0 } ] console.log(copy) // [ { a: 5, b: 0 }…
Leon Braun
  • 385
  • 5
  • 11
1
vote
4 answers

How does one map an array in order to create both a new array with changed array items but without mutating the original array or any of its items?

I have an array of objects for example I want to replace the key normal with value www.test.com/is/images/383773?@HT_dtImage. I am using .replace with regex to basically replace the wid and hei with @HT_dtImage const urls = [ {"normal":…
steven5210
  • 105
  • 10
1
vote
0 answers

Shallow copying another variable that is a shallow copy in python

a = [1,2,3] b = [a.copy(),a] c = b.copy() print(b[0] is c[0]) >>> True print(c[1] is a) >>> True Hi, I've been trying out shallow copying and I don't really understand why b[0] is c[0]. If c is a shallow copy of b, shouldn't it be independent of…
asd-qwert
  • 41
  • 5
1
vote
1 answer

Ruby object clone/copy

Overview I am creating objects in my ruby script from database queries that generates XML files. I have made it so only one XML file is processed at a time and all of the tags are generic so other queries can be added easily. Problem I am creating…
Hunter McMillen
  • 59,865
  • 24
  • 119
  • 170
1
vote
3 answers

useState results in shallow copy of initial value

I would like to pass data (which is saved as a state) to a react component that graphs that data. That graph should also be able to filter the data. The data is a nested object structured as follows. { "mylog": { "entries": [ {"Bool1":…
1
vote
1 answer

How to shallow copy of a list given as generic without knowing the items generic type parameter?

I got as far as: T clone(T source) { if(source != null && source.GetType() == typeof(List<>)) { Type listType = source.GetType(); Type listElemType = listType.GetGenericArguments()[0].GetType(); var listClone =…
Gigi
  • 158
  • 11
1
vote
0 answers

Maven release plugin - How to use shallow git clone

i'm using the maven release plugin 2.5.3. I'm using git as repo. I want to use the shallow clone (depth 1) option at the time of release plugin. I saw the shallow clone option has been introduced in maven-scm-api starting from 1.10.0 version but…
David
  • 11
  • 1
1
vote
1 answer

what's a shallow copy of a literal result element in XSLT?

regarding: A literal result element acts as an instruction to construct an element node with the same name in the result tree. The XSLT processor effectively creates a shallow copy of the literal result element from the stylesheet and …
Pacerier
  • 86,231
  • 106
  • 366
  • 634
1
vote
1 answer

Copy constructor + Shallow & deep copy

I wanted to ask that when I don't write any copy constructor explicitly so the compiler automatically generates the copy constructor which performs shallow copy by default right? So in the main() program when I changed the values of integers a, b…
1
vote
1 answer

Different types of Shallow copy [SOLVED: aliasing vs copying]

This question is not about explaining how shallow/deep work, but examples of shallow copy. I am making notes, and I wonder if these two examples both 'fall under the roof' of shallow copies. Yes, they are a little different, but are they both so…
Ana Maria
  • 475
  • 2
  • 11
1
vote
1 answer

Python alters original list despite using list.copy()

So I just encountered something weird. I had problems with copying lists and altering when I started programming, then learned that I had to use my_list.copy() to get an actual copy. Now I just stumbled upon the same effect, despite using…
n00by0815
  • 184
  • 1
  • 12
1
vote
1 answer

shallow copy in java-String variable

public class CopyByCloning implements Cloneable{ StringBuffer text; public CopyByCloning(String text) { this.text=new StringBuffer(text); } public StringBuffer getText() { return text; } public void setText(String text) { this.text…
kiki
  • 62
  • 5