Adds all the items in the list to the queue and then signals the condition variable. It is useful when the caller would like to add all of the items to the queue before consumer starts processing them.
(list []interface{})
| 162 | // variable. It is useful when the caller would like to add all of the items |
| 163 | // to the queue before consumer starts processing them. |
| 164 | func (h *Heap) BulkAdd(list []interface{}) error { |
| 165 | h.lock.Lock() |
| 166 | defer h.lock.Unlock() |
| 167 | if h.closed { |
| 168 | return fmt.Errorf(closedMsg) |
| 169 | } |
| 170 | for _, obj := range list { |
| 171 | key, err := h.data.keyFunc(obj) |
| 172 | if err != nil { |
| 173 | return KeyError{obj, err} |
| 174 | } |
| 175 | if _, exists := h.data.items[key]; exists { |
| 176 | h.data.items[key].obj = obj |
| 177 | heap.Fix(h.data, h.data.items[key].index) |
| 178 | } else { |
| 179 | h.addIfNotPresentLocked(key, obj) |
| 180 | } |
| 181 | } |
| 182 | h.cond.Broadcast() |
| 183 | return nil |
| 184 | } |
| 185 | |
| 186 | // AddIfNotPresent inserts an item, and puts it in the queue. If an item with |
| 187 | // the key is present in the map, no changes is made to the item. |