38 lines
711 B
Go
38 lines
711 B
Go
|
package meta
|
||
|
|
||
|
type ChangedFields struct {
|
||
|
fieldNames map[string]struct{}
|
||
|
}
|
||
|
|
||
|
func NewChangedFields(fieldCount int) ChangedFields {
|
||
|
cf := ChangedFields{
|
||
|
fieldNames: make(map[string]struct{}, fieldCount),
|
||
|
}
|
||
|
return cf
|
||
|
}
|
||
|
|
||
|
func (cf *ChangedFields) Reset() {
|
||
|
if cf.fieldNames == nil {
|
||
|
cf.fieldNames = make(map[string]struct{})
|
||
|
} else {
|
||
|
for k := range cf.fieldNames {
|
||
|
delete(cf.fieldNames, k)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (cf ChangedFields) Changed(field string) bool {
|
||
|
_, ok := cf.fieldNames[field]
|
||
|
return ok
|
||
|
}
|
||
|
|
||
|
func (cf *ChangedFields) SetChanged(fields ...string) {
|
||
|
for _, field := range fields {
|
||
|
cf.fieldNames[field] = struct{}{}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (cf ChangedFields) Empty() bool {
|
||
|
return len(cf.fieldNames) == 0
|
||
|
}
|