mirror of
https://github.com/MontFerret/ferret.git
synced 2025-07-15 01:25:00 +02:00
Feature/#95 deepclone (#101)
* rename method Clone to Copy * added Cloneable interface * added Value to Cloneable interface * implemented Cloneable intefrace by array * implemented Cloneable interface by Object * unit tests for Object.Clone * move core.IsCloneable to value.go * change Clone function * move IsClonable to package values
This commit is contained in:
@ -110,7 +110,7 @@ func (t *Array) Hash() uint64 {
|
||||
return h.Sum64()
|
||||
}
|
||||
|
||||
func (t *Array) Clone() core.Value {
|
||||
func (t *Array) Copy() core.Value {
|
||||
c := NewArray(len(t.value))
|
||||
|
||||
for _, el := range t.value {
|
||||
@ -206,3 +206,18 @@ func (t *Array) RemoveAt(idx Int) {
|
||||
|
||||
t.value = append(t.value[:i], t.value[i+1:]...)
|
||||
}
|
||||
|
||||
func (t *Array) Clone() core.Cloneable {
|
||||
cloned := NewArray(0)
|
||||
|
||||
var value core.Value
|
||||
for idx := NewInt(0); idx < t.Length(); idx++ {
|
||||
value = t.Get(idx)
|
||||
if IsCloneable(value) {
|
||||
value = value.(core.Cloneable).Clone()
|
||||
}
|
||||
cloned.Push(value)
|
||||
}
|
||||
|
||||
return cloned
|
||||
}
|
||||
|
Reference in New Issue
Block a user