<commit_before>package report

import (
	"bytes"
	"fmt"

	"github.com/davecgh/go-spew/spew"
	"github.com/ugorji/go/codec"
	"github.com/weaveworks/ps"

	"github.com/weaveworks/scope/test/reflect"
)

// NodeSet is a set of nodes keyed on ID. Clients must use
// the Add method to add nodes
type NodeSet struct {
	psMap ps.Map
}

var emptyNodeSet = NodeSet{ps.NewMap()}

// MakeNodeSet makes a new NodeSet with the given nodes.
func MakeNodeSet(nodes ...Node) NodeSet {
	return emptyNodeSet.Add(nodes...)
}

// Copy returns a value copy of the Nodes.
func (n NodeSet) Copy() NodeSet {
	result := ps.NewMap()
	n.ForEach(func(node Node) {
		result = result.UnsafeMutableSet(node.ID, node)
	})
	return NodeSet{result}
}

// UnsafeAdd adds a node to the NodeSet. Only call this if n has one owner.
func (n *NodeSet) UnsafeAdd(node Node) {
	if n.psMap == nil {
		n.psMap = ps.NewMap()
	}
	n.psMap = n.psMap.UnsafeMutableSet(node.ID, node)
}

// Add adds the nodes to the NodeSet, and returns the NodeSet to enable chaining.
func (n NodeSet) Add(nodes ...Node) NodeSet {
	if len(nodes) == 0 {
		return n
	}
	result := n.psMap
	if result == nil {
		result = ps.NewMap()
	}
	for _, node := range nodes {
		result = result.Set(node.ID, node)
	}
	return NodeSet{result}
}

// Delete deletes the nodes from the NodeSet by ID. Delete is the only valid
// way to shrink a NodeSet. Delete returns the NodeSet to enable chaining.
func (n NodeSet) Delete(ids ...string) NodeSet {
	if n.Size() == 0 {
		return n
	}
	result := n.psMap
	for _, id := range ids {
		result = result.Delete(id)
	}
	if result.Size() == 0 {
		return emptyNodeSet
	}
	return NodeSet{result}
}

// UnsafeMerge combines the two NodeSets, altering n
func (n *NodeSet) UnsafeMerge(other NodeSet) {
	other.psMap.ForEach(func(key string, otherVal interface{}) {
		n.psMap = n.psMap.UnsafeMutableSet(key, otherVal)
	})
}

// Merge combines the two NodeSets and returns a new result.
func (n NodeSet) Merge(other NodeSet) NodeSet {
	nSize, otherSize := n.Size(), other.Size()
	if nSize == 0 {
		return other
	}
	if otherSize == 0 {
		return n
	}
	result, iter := n.psMap, other.psMap
	if nSize < otherSize {
		result, iter = iter, result
	}
	iter.ForEach(func(key string, otherVal interface{}) {
		result = result.Set(key, otherVal)
	})
	return NodeSet{result}
}

// Lookup the node 'key'
func (n NodeSet) Lookup(key string) (Node, bool) {
	if n.psMap != nil {
		value, ok := n.psMap.Lookup(key)
		if ok {<commit_msg>Add null checks to fix querier panic<commit_after>package report

import (
	"bytes"
	"fmt"

	"github.com/davecgh/go-spew/spew"
	"github.com/ugorji/go/codec"
	"github.com/weaveworks/ps"

	"github.com/weaveworks/scope/test/reflect"
)

// NodeSet is a set of nodes keyed on ID. Clients must use
// the Add method to add nodes
type NodeSet struct {
	psMap ps.Map
}

var emptyNodeSet = NodeSet{ps.NewMap()}

// MakeNodeSet makes a new NodeSet with the given nodes.
func MakeNodeSet(nodes ...Node) NodeSet {
	return emptyNodeSet.Add(nodes...)
}

// Copy returns a value copy of the Nodes.
func (n NodeSet) Copy() NodeSet {
	result := ps.NewMap()
	n.ForEach(func(node Node) {
		result = result.UnsafeMutableSet(node.ID, node)
	})
	return NodeSet{result}
}

// UnsafeAdd adds a node to the NodeSet. Only call this if n has one owner.
func (n *NodeSet) UnsafeAdd(node Node) {
	if n.psMap == nil {
		n.psMap = ps.NewMap()
	}
	n.psMap = n.psMap.UnsafeMutableSet(node.ID, node)
}

// Add adds the nodes to the NodeSet, and returns the NodeSet to enable chaining.
func (n NodeSet) Add(nodes ...Node) NodeSet {
	if len(nodes) == 0 {
		return n
	}
	result := n.psMap
	if result == nil {
		result = ps.NewMap()
	}
	for _, node := range nodes {
		result = result.Set(node.ID, node)
	}
	return NodeSet{result}
}

// Delete deletes the nodes from the NodeSet by ID. Delete is the only valid
// way to shrink a NodeSet. Delete returns the NodeSet to enable chaining.
func (n NodeSet) Delete(ids ...string) NodeSet {
	if n.Size() == 0 {
		return n
	}
	result := n.psMap
	for _, id := range ids {
		result = result.Delete(id)
	}
	if result.Size() == 0 {
		return emptyNodeSet
	}
	return NodeSet{result}
}

// UnsafeMerge combines the two NodeSets, altering n
func (n *NodeSet) UnsafeMerge(other NodeSet) {
	if other.psMap == nil {
		return
	}
	if n.psMap == nil {
		n.psMap = ps.NewMap()
	}
	other.psMap.ForEach(func(key string, otherVal interface{}) {
		n.psMap = n.psMap.UnsafeMutableSet(key, otherVal)
	})
}

// Merge combines the two NodeSets and returns a new result.
func (n NodeSet) Merge(other NodeSet) NodeSet {
	nSize, otherSize := n.Size(), other.Size()
	if nSize == 0 {
		return other
	}
	if otherSize == 0 {
		return n
	}
	result, iter := n.psMap, other.psMap
	if nSize < otherSize {
		result, iter = iter, result
	}
	iter.ForEach(func(key string, otherVal interface{}) {
		result = result.Set(key, otherVal)
	})
	return NodeSet{result}
}

// Lookup the node 'key'
func (n NodeSet) Lookup(key string) (Node, bool) {
	if n.psMap != nil {
		value, ok := n.psMap.Lookup(key)
		if ok {
{'fraction_non_alphanumeric': 0.12887212073073867, 'fraction_numerical': 0.0019857029388403494, 'mean_word_length': 3.4223002633889377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4581702', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1850, 'n_words': 577}