// Heap returns a pprof heap dump
768913
func (d *Debug) Heap() ([]byte, error) {
	r := d.c.newRequest("GET", "/debug/pprof/heap")
	_, resp, err := d.c.doRequest(r)
	if err != nil {
		return nil, fmt.Errorf("error making request: %s", err)
	}
	defer resp.Body.Close()

	// We return a raw response because we're just passing through a response
	// from the pprof handlers
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("error decoding body: %s", err)
	}

	return body, nil
}
1059984
func (c Config) Dump(buf []byte) string {
	N := c.Width
	var out bytes.Buffer
	rowIndex := 0
	maxRowWidth := 0
	for rowIndex*N < len(buf) {
		a, b := rowIndex*N, (rowIndex+1)*N
		if b > len(buf) {
			b = len(buf)
		}
		row := buf[a:b]
		hex, ascii := printable(row)

		if len(row) < maxRowWidth {
			padding := maxRowWidth*2 + maxRowWidth/4 - len(row)*2 - len(row)/4
			hex += strings.Repeat(" ", padding)
		}
		maxRowWidth = len(row)

		fmt.Fprintf(&out, "%5d: %s | %s\n", a, hex, ascii)
		rowIndex++
	}
	return out.String()
}
386333
func (d *Context) GetHeapptr(index int) unsafe.Pointer {
	return unsafe.Pointer(C.duk_get_heapptr(d.duk_context, C.duk_idx_t(index)))
}
636801
func (h *Heap) Get(obj interface{}) (interface{}, bool, error) {
	key, err := h.data.keyFunc(obj)
	if err != nil {
		return nil, false, KeyError{obj, err}
	}
	return h.GetByKey(key)
}
776256
func (p *Prque) Remove(i int) interface{} {
	if i < 0 {
		return nil
	}
	return heap.Remove(p.cont, i)
}
437882
func (p *PodContainer) Memory(memory float64) *PodContainer {
	p.Resources.Mem = memory
	return p
}
813966
func getTopK(queue []interface{}, id *bitmap, k int) []interface{} {
	topkHeap := make(topKHeap, 0, k+1)

	for _, value := range queue {
		node := value.(*node)
		distance := id.Xor(node.id)
		if topkHeap.Len() == k {
			var last = topkHeap[topkHeap.Len() - 1]
			if last.distance.Compare(distance, maxPrefixLength) == 1 {
				item := &heapItem{
					distance,
					value,
				}
				heap.Push(&topkHeap, item)
				heap.Pop(&topkHeap)
			}
		} else {
			item := &heapItem{
				distance,
				value,
			}
			heap.Push(&topkHeap, item)
		}
	}

	tops := make([]interface{}, topkHeap.Len())
	for i := len(tops) - 1; i >= 0; i-- {
		tops[i] = heap.Pop(&topkHeap).(*heapItem).value
	}

	return tops
}
402844
func (t *TopK) Elements() []*Element {
	if t.elements.Len() == 0 {
		return make([]*Element, 0)
	}

	elements := make(elementHeap, t.elements.Len())
	copy(elements, *t.elements)
	heap.Init(&elements)
	topK := make([]*Element, 0, t.k)

	for elements.Len() > 0 {
		topK = append(topK, heap.Pop(&elements).(*Element))
	}

	return topK
}
295226
func (ha *Heap) Update() {
	ha.m.Lock()
	defer ha.m.Unlock()

	runtime.ReadMemStats(&ha.mem)
	ha.g.Update(int64(ha.mem.HeapAlloc))
}
907291
func Init(h sort.Interface) {
	// heapify
	n := h.Len()
	for i := n/2 - 1; i >= 0; i-- {
		heapDown(n, h.Less, h.Swap, i)
	}
}
656774
func (h *Heap) Close() {
	h.lock.Lock()
	defer h.lock.Unlock()
	h.closed = true
	h.cond.Broadcast()
}
773644
func (prog *Program) Load(i int) (string, syntax.Position) {
	id := prog.compiled.Loads[i]
	return id.Name, id.Pos
}
399937
func (world *World) Malloc(flags uint, size uint) *Memory {
	return &Memory{world, size}
}
1152598
func (h *heap) extractMax() {
	if len(h.tree) == 0 {
		return
	}

	h.tree[0] = h.tree[len(h.tree)-1]
	h.tree = h.tree[:len(h.tree)-1]

	target := 1
	for true {
		largest := target
		if target*2-1 >= len(h.tree) {
			break
		}
		if h.tree[target*2-1].length > h.tree[target-1].length {
			largest = target * 2
		}

		if target*2 < len(h.tree) {
			if h.tree[target*2].length > h.tree[largest-1].length {
				largest = target*2 + 1
			}
		}

		if largest == target {
			break
		}
		h.tree[largest-1], h.tree[target-1] = h.tree[target-1], h.tree[largest-1]
		target = largest
	}
}
145614
func (met *Metrics) Dump() ([]byte, error) {
	snapshot := make(map[string]int64)

	met.storeGuard.RLock()
	for key, value := range met.store {
		snapshot[key] = atomic.LoadInt64(value)
	}
	met.storeGuard.RUnlock()

	met.rateGuard.RLock()
	for key, rate := range met.rates {
		snapshot[key] = rate.value
	}
	met.rateGuard.RUnlock()

	return json.Marshal(snapshot)
}
876272
func (e *Env) Dump() {
	e.RLock()
	fmt.Printf("Name: %v\n", e.name)
	fmt.Printf("Has parent: %v\n", e.parent != nil)
	for k, v := range e.env {
		fmt.Printf("%v = %#v\n", k, v)
	}
	e.RUnlock()
}
963856
func (r *Resp) Dump() string {
	dump := new(dumpBuffer)
	if r.r.flag&Lcost != 0 {
		dump.WriteString(fmt.Sprint(r.cost))
	}
	r.dumpRequest(dump)
	l := dump.Len()
	if l > 0 {
		dump.WriteString("=================================")
		l = dump.Len()
	}

	r.dumpResponse(dump)

	return dump.String()
}