Add Clone to Lists #150

Closed
AryanAhadinia wants to merge 4 commits from issue_97 into master
AryanAhadinia commented 2021-01-14 09:21:28 +00:00 (Migrated from github.com)

Issue #97

Issue #97
emirpasic commented 2022-04-12 03:20:41 +00:00 (Migrated from github.com)

The requested functionality already exists (shown here two options):

package main

import (
	"fmt"
	"github.com/emirpasic/gods/lists/arraylist"
)

// ArrayListExample to demonstrate basic usage of ArrayList
func main() {
	list := arraylist.New()
	list.Add("a", "b", "c")

	// Option 1 (advantage: faster memory allocation | disadvantage: uses extra memory)
	clone1 := arraylist.New(list.Values()...)
	fmt.Println(clone1.Size())

	// Option 2 (advantage: no extra memory used | disadvantage: slow memory allocation due to list growth)
	clone2 := arraylist.New()
	for it := list.Iterator(); it.Next(); {
		clone2.Add(it.Value())
	}
	fmt.Println(clone2.Size())
}
The requested functionality already exists (shown here two options): ```go package main import ( "fmt" "github.com/emirpasic/gods/lists/arraylist" ) // ArrayListExample to demonstrate basic usage of ArrayList func main() { list := arraylist.New() list.Add("a", "b", "c") // Option 1 (advantage: faster memory allocation | disadvantage: uses extra memory) clone1 := arraylist.New(list.Values()...) fmt.Println(clone1.Size()) // Option 2 (advantage: no extra memory used | disadvantage: slow memory allocation due to list growth) clone2 := arraylist.New() for it := list.Iterator(); it.Next(); { clone2.Add(it.Value()) } fmt.Println(clone2.Size()) } ```

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
golibs/gms-gods!150
No description provided.