goc2p icon indicating copy to clipboard operation
goc2p copied to clipboard

Incorrect definition of `IsSuperset` !

Open minghu6 opened this issue 9 years ago • 0 comments

code in basic/set

// 判断集合 one 是否是集合 other 的超集
func IsSuperset(one Set, other Set) bool {
	if one == nil || other == nil {
		return false
	}
	oneLen := one.Len()
	otherLen := other.Len()
	if oneLen == 0 || oneLen == otherLen {
		return false
	}
	if oneLen > 0 && otherLen == 0 {
		return true
	}
	for _, v := range other.Elements() {
		if !one.Contains(v) {
			return false
		}
	}
	return true
}

Proper super set is not equivalent of super set. In other words, if one == other, then one issuperset of other(just like Python set.issuperset method).

	if oneLen == 0 || oneLen == otherLen {
		return false
	}

minghu6 avatar Dec 29 '16 06:12 minghu6