<commit_before>// Copyright 2014 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License. See the AUTHORS file
// for names of contributors.
//
// Author: <NAME> (<EMAIL>)

package proto

import (
	"github.com/cockroachdb/cockroach/util"
	gogoproto "github.com/gogo/protobuf/proto"
)

// TODO(spencer): change these string constants into a type.
const (
	// Contains determines whether the KV map contains the specified key.
	Contains = "Contains"
	// Get fetches the value for a key from the KV map, respecting a
	// possibly historical timestamp. If the timestamp is 0, returns
	// the most recent value.
	Get = "Get"
	// Put sets the value for a key at the specified timestamp. If the
	// timestamp is 0, the value is set with the current time as timestamp.
	Put = "Put"
	// ConditionalPut sets the value for a key if the existing value
	// matches the value specified in the request. Specifying a null value
	// for existing means the value must not yet exist.
	ConditionalPut = "ConditionalPut"
	// Increment increments the value at the specified key. Once called
	// for a key, Put & Get will return errors; only Increment will
	// continue to be a valid command. The value must be deleted before
	// it can be reset using Put.
	Increment = "Increment"
	// Delete removes the value for the specified key.
	Delete = "Delete"
	// DeleteRange removes all values for keys which fall between
	// args.RequestHeader.Key and args.RequestHeader.EndKey, with
	// the latter endpoint excluded.
	DeleteRange = "DeleteRange"
	// Scan fetches the values for all keys which fall between
	// args.RequestHeader.Key and args.RequestHeader.EndKey, with
	// the latter endpoint excluded.
	Scan = "Scan"
	// EndTransaction either commits or aborts an ongoing transaction.
	EndTransaction = "EndTransaction"
	// ReapQueue scans and deletes messages from a recipient message
	// queue. ReapQueueRequest invocations must be part of an extant
	// transaction or they fail. Returns the reaped queue messsages, up to
	// the requested maximum. If fewer than the maximum were returned,
	// then the queue is empty.
	ReapQueue = "ReapQueue"
	// EnqueueUpdate enqueues an update for eventual execution.
	EnqueueUpdate = "EnqueueUpdate"
	// EnqueueMessage enqueues a message for delivery to an inbox.
	EnqueueMessage = "EnqueueMessage"
	// Batch executes a set of commands in parallel.
	Batch = "Batch"
	// AdminSplit is called to coordinate a split of a range.
	AdminSplit = "AdminSplit"
	// AdminMerge is called to coordinate a merge of two adjacent ranges.
	AdminMerge = "AdminMerge"
)

type stringSet map[string]struct{}

func (s stringSet) keys() []string {
	keys := make([]string, 0, len(s))
	for k := range s {
		keys = append(keys, k)
	}
	return keys
}

// TODO(spencer): replaces these individual maps with a bitmask or
//   equivalent listing each method's attributes.

// AllMethods specifies the complete set of methods.
var AllMethods = stringSet{
	Contains:               struct{}{},
	Get:                    struct{}{},
	Put:                    struct{}{},
	ConditionalPut:         struct{}{},
	Increment:              struct{}{},
	Delete:                 struct{}{},
	DeleteRange:            struct{}{},
	Scan:                   struct{}{},
	EndTransaction:         struct{}{},
	ReapQueue:              struct{}{},
	EnqueueUpdate:          struct{}{},
	EnqueueMessage:         struct{}{},
	AdminSplit:             struct{}{},
	AdminMerge:             struct{}{},
	Batch:                  struct{}{},
	InternalHeartbeatTxn:   struct{}{},
	InternalGC:             struct{}{},
	InternalPushTxn:        struct{}{},
	InternalResolveIntent:  struct{}{},
	InternalMerge:          struct{}{},
	InternalTruncateLog:    struct{}{},
	InternalChangeReplicas: struct{}{},
}

// PublicMethods specifies the set of methods accessible via the
// public key-value API.
var PublicMethods = stringSet{
	Contains:       struct{}{},
	Get:            struct{}{},
	Put:            struct{}{},
	ConditionalPut: struct{}{},
	Increment:      struct{}{},
	Delete:         struct{}{},
	DeleteRange:    struct{}{},
	Scan:           struct{}{},
	EndTransaction: struct{}{},
	ReapQueue:      struct{}{},
	EnqueueUpdate:  struct{}{},
	EnqueueMessage: struct{}{},
	Batch:          struct{}{},
	AdminSplit:     struct{}{},
}

// InternalMethods specifies the set of methods accessible only
// via the internal node RPC API.
var InternalMethods = stringSet{
	InternalHeartbeatTxn:   struct{}{},
	InternalGC:             struct{}{},
	InternalPushTxn:        struct{}{},
	InternalResolveIntent:  struct{}{},
	InternalMerge:          struct{}{},
	InternalTruncateLog:    struct{}{},
	InternalChangeReplicas: struct{}{},
}

// ReadMethods specifies the set of methods which read and return data.
var ReadMethods = stringSet{
	Contains:            struct{}{},
	Get:                 struct{}{},
	ConditionalPut:      struct{}{},
	Increment:           struct{}{},
	Scan:                struct{}{},
	ReapQueue:           struct{}{},
	InternalRangeLookup: struct{}{},
}

// WriteMethods specifies the set of methods which write data.
var WriteMethods = stringSet{
	Put:                    struct{}{},
	ConditionalPut:         struct{}{},
	Increment:              struct{}{},
	Delete:                 struct{}{},
	DeleteRange:            struct{}{},
	EndTransaction:         struct{}{},
	ReapQueue:              struct{}{},
	EnqueueUpdate:          struct{}{},
	EnqueueMessage:         struct{}{},
	Batch:                  struct{}{},
	InternalHeartbeatTxn:   struct{}{},
	InternalGC:             struct{}{},
	InternalPushTxn:        struct{}{},
	InternalResolveIntent:  struct{}{},
	InternalMerge:          struct{}{},
	InternalTruncateLog:    struct{}{},
	InternalChangeReplicas: struct{}{},
}

// TxnMethods specifies the set of methods which leave key intents
// during transactions.
var TxnMethods = stringSet{
	Put:            struct{}{},
	ConditionalPut: struct{}{},
	Increment:      struct{}{},
	Delete:         struct{}{},
	DeleteRange:    struct{}{},
	ReapQueue:      struct{}{},
	EnqueueUpdate:  struct{}{},
	EnqueueMessage: struct{}{},
}

// adminMethods specifies the set of methods which are neither
// read-only nor read-write commands but instead execute directly on
// the Raft leader.
var adminMethods = stringSet{
	AdminSplit: struct{}{},
	AdminMerge: struct{}{},
}

// NeedReadPerm returns true if the specified method requires read permissions.
func NeedReadPerm(method string) bool {
	_, ok := ReadMethods[method]
	return ok
}

// NeedWritePerm returns true if the specified method requires write permissions.
func NeedWritePerm(method string) bool {
	_, ok := WriteMethods[method]
	return ok
}

// NeedAdminPerm returns true if the specified method requires admin permissions.
func NeedAdminPerm(method string) bool {
	_, ok := adminMethods[method]
	return ok
}
<commit_msg>Remove inferrable types from stringSet construction.<commit_after>// Copyright 2014 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License. See the AUTHORS file
// for names of contributors.
//
// Author: <NAME> (<EMAIL>)

package proto

import (
	"github.com/cockroachdb/cockroach/util"
	gogoproto "github.com/gogo/protobuf/proto"
)

// TODO(spencer): change these string constants into a type.
const (
	// Contains determines whether the KV map contains the specified key.
	Contains = "Contains"
	// Get fetches the value for a key from the KV map, respecting a
	// possibly historical timestamp. If the timestamp is 0, returns
	// the most recent value.
	Get = "Get"
	// Put sets the value for a key at the specified timestamp. If the
	// timestamp is 0, the value is set with the current time as timestamp.
	Put = "Put"
	// ConditionalPut sets the value for a key if the existing value
	// matches the value specified in the request. Specifying a null value
	// for existing means the value must not yet exist.
	ConditionalPut = "ConditionalPut"
	// Increment increments the value at the specified key. Once called
	// for a key, Put & Get will return errors; only Increment will
	// continue to be a valid command. The value must be deleted before
	// it can be reset using Put.
	Increment = "Increment"
	// Delete removes the value for the specified key.
	Delete = "Delete"
	// DeleteRange removes all values for keys which fall between
	// args.RequestHeader.Key and args.RequestHeader.EndKey, with
	// the latter endpoint excluded.
	DeleteRange = "DeleteRange"
	// Scan fetches the values for all keys which fall between
	// args.RequestHeader.Key and args.RequestHeader.EndKey, with
	// the latter endpoint excluded.
	Scan = "Scan"
	// EndTransaction either commits or aborts an ongoing transaction.
	EndTransaction = "EndTransaction"
	// ReapQueue scans and deletes messages from a recipient message
	// queue. ReapQueueRequest invocations must be part of an extant
	// transaction or they fail. Returns the reaped queue messsages, up to
	// the requested maximum. If fewer than the maximum were returned,
	// then the queue is empty.
	ReapQueue = "ReapQueue"
	// EnqueueUpdate enqueues an update for eventual execution.
	EnqueueUpdate = "EnqueueUpdate"
	// EnqueueMessage enqueues a message for delivery to an inbox.
	EnqueueMessage = "EnqueueMessage"
	// Batch executes a set of commands in parallel.
	Batch = "Batch"
	// AdminSplit is called to coordinate a split of a range.
	AdminSplit = "AdminSplit"
	// AdminMerge is called to coordinate a merge of two adjacent ranges.
	AdminMerge = "AdminMerge"
)

type stringSet map[string]struct{}

func (s stringSet) keys() []string {
	keys := make([]string, 0, len(s))
	for k := range s {
		keys = append(keys, k)
	}
	return keys
}

// TODO(spencer): replaces these individual maps with a bitmask or
//   equivalent listing each method's attributes.

// AllMethods specifies the complete set of methods.
var AllMethods = stringSet{
	Contains:               {},
	Get:                    {},
	Put:                    {},
	ConditionalPut:         {},
	Increment:              {},
	Delete:                 {},
	DeleteRange:            {},
	Scan:                   {},
	EndTransaction:         {},
	ReapQueue:              {},
	EnqueueUpdate:          {},
	EnqueueMessage:         {},
	AdminSplit:             {},
	AdminMerge:             {},
	Batch:                  {},
	InternalHeartbeatTxn:   {},
	InternalGC:             {},
	InternalPushTxn:        {},
	InternalResolveIntent:  {},
	InternalMerge:          {},
	InternalTruncateLog:    {},
	InternalChangeReplicas: {},
}

// PublicMethods specifies the set of methods accessible via the
// public key-value API.
var PublicMethods = stringSet{
	Contains:       {},
	Get:            {},
	Put:            {},
	ConditionalPut: {},
	Increment:      {},
	Delete:         {},
	DeleteRange:    {},
	Scan:           {},
	EndTransaction: {},
	ReapQueue:      {},
	EnqueueUpdate:  {},
	EnqueueMessage: {},
	Batch:          {},
	AdminSplit:     {},
}

// InternalMethods specifies the set of methods accessible only
// via the internal node RPC API.
var InternalMethods = stringSet{
	InternalHeartbeatTxn:   {},
	InternalGC:             {},
	InternalPushTxn:        {},
	InternalResolveIntent:  {},
	InternalMerge:          {},
	InternalTruncateLog:    {},
	InternalChangeReplicas: {},
}

// ReadMethods specifies the set of methods which read and return data.
var ReadMethods = stringSet{
	Contains:            {},
	Get:                 {},
	ConditionalPut:      {},
	Increment:           {},
	Scan:                {},
	ReapQueue:           {},
	InternalRangeLookup: {},
}

// WriteMethods specifies the set of methods which write data.
var WriteMethods = stringSet{
	Put:                    {},
	ConditionalPut:         {},
	Increment:              {},
	Delete:                 {},
	DeleteRange:            {},
	EndTransaction:         {},
	ReapQueue:              {},
	EnqueueUpdate:          {},
	EnqueueMessage:         {},
	Batch:                  {},
	InternalHeartbeatTxn:   {},
	InternalGC:             {},
	InternalPushTxn:        {},
	InternalResolveIntent:  {},
	InternalMerge:          {},
	InternalTruncateLog:    {},
	InternalChangeReplicas: {},
}

// TxnMethods specifies the set of methods which leave key intents
// during transactions.
var TxnMethods = stringSet{
	Put:            {},
	ConditionalPut: {},
	Increment:      {},
	Delete:         {},
	DeleteRange:    {},
	ReapQueue:      {},
	EnqueueUpdate:  {},
	EnqueueMessage: {},
}

// adminMethods specifies the set of methods which are neither
// read-only nor read-write commands but instead execute directly on
// the Raft leader.
var adminMethods = stringSet{
	AdminSplit: {},
	AdminMerge: {},
}

// NeedReadPerm returns true if the specified method requires read permissions.
func NeedReadPerm(method string) bool {
	_, ok := ReadMethods[method]
	return ok
}

// NeedWritePerm returns true if the specified method requires write permissions.
func NeedWritePerm(method string) bool {
	_, ok := WriteMethods[method]
	return ok
}

// NeedAdminPerm returns true if the specified method requires admin permissions.
func NeedAdminPerm(method string) bool {
	_, ok := adminMethods[method]
	return ok
}

{'fraction_non_alphanumeric': 0.1064190382035167, 'fraction_numerical': 0.0015535626015111927, 'mean_word_length': 2.8620125443141533, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6290252', 'n_tokens_mistral': 3897, 'n_tokens_neox': 3816, 'n_words': 1452}