// RemoveOld removes from the list those members which are not present in the given list.
// It always should leave at least one element. The config won't be valid for mongo otherwise.
// Better, if the last element has the smallest ID in order not to produce defragmentation
// when the next element will be added (ID = maxID + 1). Mongo replica set member ID must be between 0 and 255, so it matters.
RemoveOld removes from the list those members which are not present in the given list.
It always should leave at least one element. The config won't be valid for mongo otherwise.
Better, if the last element has the smallest ID in order not to produce defragmentation
when the next element will be added (ID = maxID + 1). Mongo replica set member ID must be between 0 and 255, so it matters.
// RemoveOld removes from the list those members which are not present in the given list . // It always should leave at least one element . The config won ' t be valid for mongo otherwise . // Better if the last element has the smallest ID in order not to produce defragmentation // when the next element will be added ( ID = maxID + 1 ) . Mongo replica set member ID must be between 0 and 255 so it matters .
func (m *RSMembers) RemoveOld(compareWith RSMembers) (changes bool) {
	cm := make(map[string]struct{}, len(compareWith))
	for _, member := range compareWith {
		cm[member.Host] = struct{}{}
	}
	for i := len(*m) - 1; i >= 0 && len(*m) > 1; i-- {
		member := []Member(*m)[i]
		if _, ok := cm[member.Host]; !ok {
			*m = append([]Member(*m)[:i], []Member(*m)[i+1:]...)
			changes = true
		}
	}
	return changes
}
func ( m * RSMembers ) RemoveOld ( compareWith RSMembers ) ( changes bool ) { cm := make ( map [ string ] struct { } , len ( compareWith ) ) for _ , member := range compareWith { cm [ member . Host ] = struct { } { } } for i := len ( * m ) - 1 ; i >= 0 && len ( * m ) > 1 ; i -- { member := [ ] Member ( * m ) [ i ] if _ , ok := cm [ member . Host ] ; ! ok { * m = append ( [ ] Member ( * m ) [ : i ] , [ ] Member ( * m ) [ i + 1 : ] ... ) changes = true } } return changes }
RemoveOld removes from the list those members which are not present in the given list.
RemoveOld removes from the list those members which are not present in the given list .
// going from the end to the starting in order to leave last element with the smallest id