<commit_before>package nodeID

import (
	"bytes"
	"encoding/hex"
	"errors"
	xu "github.com/jddixon/xlattice_go/util"
)

// TAKE CARE: these in bytes; hex values are twice these
const SHA1_LEN = 20
const SHA3_LEN = 32

// CONSTRUCTORS /////////////////////////////////////////////////////
type NodeID struct {
	_nodeID []byte
}

var (
	BadNodeIDLen = errors.New("bad length for nodeID")
	NilNodeID    = errors.New("nil byte array for nodeID")
)

func New(id []byte) (q *NodeID, err error) {
	if id == nil {
		err = NilNodeID
	} else {
		q = new(NodeID)
		// deep copy the slice
		size := len(id)
		myID := make([]byte, size)
		for i := 0; i < size; i++ {
			myID[i] = id[i]
		}
		q._nodeID = myID
		if !IsValidID(id) {
			err = BadNodeIDLen
		}
	}
	return
}

// XXX CONSIDER ME DEPRECATED
func NewNodeID(id []byte) (q *NodeID, err error) {
	return New(id)
}

// func NewNodeIDFromString(id string) *NodeID {
//     ...
// }

func (n *NodeID) Clone() (*NodeID, error) {
	v := n.Value()
	return NewNodeID(v)
}

// OTHER METHODS ////////////////////////////////////////////////////
func (n *NodeID) Compare(any interface{}) (int, error) {
	result := 0
	err := error(nil)
	if any == nil {
		err = errors.New("IllegalArgument: nil comparand")
	} else if any == n {
		return result, err // defaults to 0, nil
	} else {
		switch v := any.(type) {
		case *NodeID:
			_ = v
		default:<commit_msg>New accepts nil parameter, produces 256-bit value by default<commit_after>package nodeID

import (
	"bytes"
	"encoding/hex"
	"errors"
	xr "github.com/jddixon/xlattice_go/rnglib"
	xu "github.com/jddixon/xlattice_go/util"
)

// TAKE CARE: these in bytes; hex values are twice these
const SHA1_LEN = 20
const SHA3_LEN = 32

// CONSTRUCTORS /////////////////////////////////////////////////////
type NodeID struct {
	_nodeID []byte
}

var (
	BadNodeIDLen = errors.New("bad length for nodeID")
	NilNodeID    = errors.New("nil byte array for nodeID")
)

func New(id []byte) (q *NodeID, err error) {
	q = new(NodeID)
	if id == nil {
		id = make([]byte, SHA3_LEN)
		rng := xr.MakeSystemRNG()
		rng.NextBytes(&id)
		q._nodeID = id
	} else {
		// deep copy the slice
		size := len(id)
		myID := make([]byte, size)
		for i := 0; i < size; i++ {
			myID[i] = id[i]
		}
		q._nodeID = myID
	}
	if !IsValidID(id) {
		err = BadNodeIDLen
	}
	return
}

// XXX CONSIDER ME DEPRECATED
func NewNodeID(id []byte) (q *NodeID, err error) {
	return New(id)
}

// func NewNodeIDFromString(id string) *NodeID {
//     ...
// }

func (n *NodeID) Clone() (*NodeID, error) {
	v := n.Value()
	return NewNodeID(v)
}

// OTHER METHODS ////////////////////////////////////////////////////
func (n *NodeID) Compare(any interface{}) (int, error) {
	result := 0
	err := error(nil)
	if any == nil {
		err = errors.New("IllegalArgument: nil comparand")
	} else if any == n {
		return result, err // defaults to 0, nil
	} else {
		switch v := any.(type) {
		case *NodeID:
			_ = v
		default:
{'fraction_non_alphanumeric': 0.21178072863466121, 'fraction_numerical': 0.00749063670411985, 'mean_word_length': 2.3692660550458715, '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': '697851', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1082, 'n_words': 309}