code: func (p *MemPostings) Delete(deleted map[uint64]struct{}) {
  	var keys, vals []string
  
  	// Collect all keys relevant for deletion once. New keys added afterwards
  	// can by definition not be affected by any of the given deletes.
  	p.mtx.RLock()
  	for n := range p.m {
  		keys = append(keys, n)
  	}
  	p.mtx.RUnlock()
  
  	for _, n := range keys {
  		p.mtx.RLock()
  		vals = vals[:0]
  		for v := range p.m[n] {
  			vals = append(vals, v)
  		}
  		p.mtx.RUnlock()
  
  		// For each posting we first analyse whether the postings list is affected by the deletes.
  		// If yes, we actually reallocate a new postings list.
  		for _, l := range vals {
  			// Only lock for processing one postings list so we don't block reads for too long.
  			p.mtx.Lock()
  
  			found := false
  			for _, id := range p.m[n][l] {
  				if _, ok := deleted[id]; ok {
  					found = true
  					break
  				}
  			}
  			if !found {
  				p.mtx.Unlock()
  				continue
  			}
  			repl := make([]uint64, 0, len(p.m[n][l]))
  
  			for _, id := range p.m[n][l] {
  				if _, ok := deleted[id]; !ok {
  					repl = append(repl, id)
  				}
  			}
  			if len(repl) > 0 {
  				p.m[n][l] = repl
  			} else {
  				delete(p.m[n], l)
  			}
  			p.mtx.Unlock()
  		}
  		p.mtx.Lock()
  		if len(p.m[n]) == 0 {
  			delete(p.m, n)
  		}
  		p.mtx.Unlock()
  	}
  }
docs: // Delete removes all ids in the given map from the postings lists.