// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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.

//go:build go1.18

package compute

import (
	

	
	
)

var (
	runEndEncodeDoc = FunctionDoc{
		Summary:         "Run-end encode array",
		Description:     "Return a run-end encoded version of the input array",
		ArgNames:        []string{"array"},
		OptionsType:     "RunEndEncodeOptions",
		OptionsRequired: true,
	}
	runEndDecodeDoc = FunctionDoc{
		Summary:     "Decode run-end encoded array",
		Description: "Return a decoded version of a run-end encoded input array",
		ArgNames:    []string{"array"},
	}
)

type RunEndEncodeOptions = kernels.RunEndEncodeState

func ( FunctionRegistry) {
	,  := kernels.GetRunEndEncodeKernels()
	 := NewVectorFunction("run_end_encode", Unary(), runEndEncodeDoc)
	for ,  := range  {
		if  := .AddKernel();  != nil {
			panic()
		}
	}
	.AddFunction(, false)

	 := NewVectorFunction("run_end_decode", Unary(), runEndDecodeDoc)
	for ,  := range  {
		if  := .AddKernel();  != nil {
			panic()
		}
	}
	.AddFunction(, false)
}

func ( context.Context,  RunEndEncodeOptions,  Datum) (Datum, error) {
	return CallFunction(, "run_end_encode", &, )
}

func ( context.Context,  RunEndEncodeOptions,  arrow.Array) (arrow.Array, error) {
	,  := RunEndEncode(, , &ArrayDatum{Value: .Data()})
	if  != nil {
		return nil, 
	}
	defer .Release()

	return .(*ArrayDatum).MakeArray(), nil
}

func ( context.Context,  Datum) (Datum, error) {
	return CallFunction(, "run_end_decode", nil, )
}

func ( context.Context,  arrow.Array) (arrow.Array, error) {
	,  := RunEndDecode(, &ArrayDatum{Value: .Data()})
	if  != nil {
		return nil, 
	}
	defer .Release()

	return .(*ArrayDatum).MakeArray(), nil
}