46 lines
857 B
Go
46 lines
857 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) {
|
|
if cf.fieldNames == nil {
|
|
cf.fieldNames = make(map[string]struct{})
|
|
}
|
|
|
|
for _, field := range fields {
|
|
cf.fieldNames[field] = struct{}{}
|
|
}
|
|
}
|
|
|
|
func (cf ChangedFields) Empty() bool {
|
|
return len(cf.fieldNames) == 0
|
|
}
|
|
|
|
func (cf ChangedFields) IsNil() bool {
|
|
return cf.fieldNames == nil
|
|
}
|