package models

import "reflect"

//const keyname string = "id"

func Differ(sl1 []IP, sl2 []IP) (toinsert []IP, err error) {
	var m = make(map[string]IPDiffer)
	longslice := append(sl1, sl2...)

	for _, v2 := range longslice {
		if _, v := m[v2.IP]; !v {
			m[v2.IP] = IPDiffer{IP: v2, Num: 1}
		} else {
			if this, ok := m[v2.IP]; ok {
				this.Num++
				m[v2.IP] = this
			}
		}
	}

	for _, j := range reflect.ValueOf(m).MapKeys() {
		if m[j.String()].Num == 1 {
			toinsert = append(toinsert, m[j.String()].IP)
		}
	}
	return
}

type IPDiffer struct {
	IP  IP
	Num int
}
