TheAlgorithms/Go

go1.18: change `interface{}` to `any`

raklaptudirm opened this issue · 9 comments

Change usage of interface{} to any using the new go1.18 alias.

CONTRIBUTING.md:func Fprint(w io.Writer, a ...interface{}) (n int, err error) {
graph/dijkstra.go:func (a Item) More(b interface{}) bool {
sort/heapsort.go:       More(interface{}) bool
sort/heapsort.go:func (a Int) More(b interface{}) bool {
structure/dynamicarray/dynamicarray.go: ElementData []interface{}
structure/dynamicarray/dynamicarray.go:func (da *DynamicArray) Put(index int, element interface{}) error {
structure/dynamicarray/dynamicarray.go:func (da *DynamicArray) Add(element interface{}) {
structure/dynamicarray/dynamicarray.go:func (da *DynamicArray) Get(index int) (interface{}, error) {
structure/dynamicarray/dynamicarray.go:func (da *DynamicArray) GetData() []interface{} {
structure/dynamicarray/dynamicarray.go: newDataElement := make([]interface{}, da.Capacity)
structure/dynamicarray/dynamicarray_test.go:            var res []interface{}
structure/dynamicarray/dynamicarray_test.go:            var res []interface{}
structure/hashmap/hashmap.go:   key   interface{}
structure/hashmap/hashmap.go:   value interface{}
structure/hashmap/hashmap.go:func (hm *HashMap) Get(key interface{}) interface{} {
structure/hashmap/hashmap.go:func (hm *HashMap) Put(key interface{}, value interface{}) interface{} {
structure/hashmap/hashmap.go:func (hm *HashMap) Contains(key interface{}) bool {
structure/hashmap/hashmap.go:func (hm *HashMap) putValue(hash uint64, key interface{}, value interface{}) interface{} {
structure/hashmap/hashmap.go:func newNode(key interface{}, value interface{}) *node {
structure/hashmap/hashmap.go:func newNodeWithNext(key interface{}, value interface{}, next *node) *node {
structure/hashmap/hashmap.go:func (hm *HashMap) hash(key interface{}) uint64 {
structure/hashmap/hashmap_test.go:              want := interface{}(nil)
structure/linkedlist/cyclic.go:func (cl *Cyclic) Add(val interface{}) {
structure/linkedlist/cyclic_test.go:    want := []interface{}{1, 2, 3}
structure/linkedlist/cyclic_test.go:    var got []interface{}
structure/linkedlist/doubly.go:func (ll *Doubly) AddAtBeg(val interface{}) {
structure/linkedlist/doubly.go:func (ll *Doubly) AddAtEnd(val interface{}) {
structure/linkedlist/doubly.go:func (ll *Doubly) DelAtBeg() interface{} {
structure/linkedlist/doubly.go:func (ll *Doubly) DelAtEnd() interface{} {
structure/linkedlist/doubly.go:func (ll *Doubly) Count() interface{} {
structure/linkedlist/shared.go: Val  interface{}
structure/linkedlist/shared.go:func NewNode(val interface{}) *Node {
structure/linkedlist/singlylinkedlist.go:func (ll *Singly) AddAtBeg(val interface{}) {
structure/linkedlist/singlylinkedlist.go:func (ll *Singly) AddAtEnd(val interface{}) {
structure/linkedlist/singlylinkedlist.go:func (ll *Singly) DelAtBeg() interface{} {
structure/linkedlist/singlylinkedlist.go:func (ll *Singly) DelAtEnd() interface{} {
structure/linkedlist/singlylinkedlist_test.go:          want := []interface{}{3, 2, 1}
structure/linkedlist/singlylinkedlist_test.go:          got := []interface{}{}
structure/linkedlist/singlylinkedlist_test.go:          want := []interface{}{3, 2, 1, 4}
structure/linkedlist/singlylinkedlist_test.go:          got := []interface{}{}
structure/linkedlist/singlylinkedlist_test.go:          want := interface{}(3)
structure/linkedlist/singlylinkedlist_test.go:          want := interface{}(4)
structure/linkedlist/singlylinkedlist_test.go:          want := []interface{}{1, 2, 3, 4, 5, 6}
structure/linkedlist/singlylinkedlist_test.go:          got := []interface{}{}
structure/linkedlist/singlylinkedlist_test.go:          want := []interface{}{1, 5, 4, 3, 2, 6}
structure/linkedlist/singlylinkedlist_test.go:          got := []interface{}{}
structure/queue/queuearray.go:var ListQueue []interface{}
structure/queue/queuearray.go:func EnQueue(n interface{}) {
structure/queue/queuearray.go:func DeQueue() interface{} {
structure/queue/queuearray.go:func FrontQueue() interface{} {
structure/queue/queuearray.go:func BackQueue() interface{} {
structure/queue/queuelinkedlist.go:     Data interface{}
structure/queue/queuelinkedlist.go:func (ll *Queue) enqueue(n interface{}) {
structure/queue/queuelinkedlist.go:func (ll *Queue) dequeue() interface{} {
structure/queue/queuelinkedlist.go:func (ll *Queue) frontQueue() interface{} {
structure/queue/queuelinkedlist.go:func (ll *Queue) backQueue() interface{} {
structure/queue/queuelinklistwithlist.go:func (lq *LQueue) Enqueue(value interface{}) {
structure/queue/queuelinklistwithlist.go:func (lq *LQueue) Front() (interface{}, error) {
structure/queue/queuelinklistwithlist.go:func (lq *LQueue) Back() (interface{}, error) {
structure/queue/queue_test.go:          ListQueue = []interface{}{}
structure/queue/queue_test.go:          ListQueue = []interface{}{}
structure/set/set.go:func New(items ...interface{}) Set {
structure/set/set.go:           elements: make(map[interface{}]bool),
structure/set/set.go:   Add(item interface{})
structure/set/set.go:   Delete(item interface{})
structure/set/set.go:   // GetItems: gives the array( []interface{} ) of elements of the set.
structure/set/set.go:   GetItems() []interface{}
structure/set/set.go:   In(item interface{}) bool
structure/set/set.go:   elements map[interface{}]bool
structure/set/set.go:func (st *set) Add(value interface{}) {
structure/set/set.go:func (st *set) Delete(value interface{}) {
structure/set/set.go:func (st *set) GetItems() []interface{} {
structure/set/set.go:   keys := make([]interface{}, 0, len(st.elements))
structure/set/set.go:func (st *set) In(value interface{}) bool {
structure/stack/stackarray.go:var stackArray []interface{}
structure/stack/stackarray.go:func stackPush(n interface{}) {
structure/stack/stackarray.go:  stackArray = append([]interface{}{n}, stackArray...)
structure/stack/stackarray.go:func stackPeak() interface{} {
structure/stack/stackarray.go:func stackPop() interface{} {
structure/stack/stacklinkedlist.go:     Val  interface{}
structure/stack/stacklinkedlist.go:func (ll *Stack) push(n interface{}) {
structure/stack/stacklinkedlist.go:func (ll *Stack) pop() interface{} {
structure/stack/stacklinkedlist.go:func (ll *Stack) peak() interface{} {
structure/stack/stacklinkedlist.go:func (ll *Stack) show() (in []interface{}) {
structure/stack/stacklinkedlistwithlist.go:func (sl *SList) Push(val interface{}) {
structure/stack/stacklinkedlistwithlist.go:func (sl *SList) Peak() (interface{}, error) {
structure/stack/stacklinkedlistwithlist.go:func (sl *SList) Pop() (interface{}, error) {
structure/stack/stack_test.go:          expected := []interface{}{2, 1}
structure/stack/stack_test.go:                  if !reflect.DeepEqual([]interface{}{3, 2}, stackArray) {
structure/stack/stack_test.go:                          t.Errorf("Stack Push is not work we expected %v but got %v", []interface{}{3, 2}, stackArray)

So it means wherever interface{} is used, it must be replaced by any. Right?

Can I take up the issue?

@raklaptudirm the picture you have put shows all the files and folders that include interface{} keyword. Right?

Yes, and it is just text, so you can copy it if you need.

Sure. Thanks

@raklaptudirm in structure/hashmap/hashmap.go there are 16 interface{} keywords but you've put only 8 of them. Is it intentional?

No, change all instances to any.

Done already.