github.com/searKing/golang/go@v1.2.74/util/object/index.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package object
     6  
     7  import (
     8  	"github.com/searKing/golang/go/util/object/internal/preconditions"
     9  )
    10  
    11  // Checks if the {@code index} is within the bounds of the range from
    12  // {@code 0} (inclusive) to {@code length} (exclusive).
    13  func CheckIndex(index, length int) int {
    14  	return preconditions.CheckIndex(index, length)
    15  }
    16  
    17  // Checks if the sub-range from {@code fromIndex} (inclusive) to
    18  // {@code toIndex} (exclusive) is within the bounds of range from {@code 0}
    19  // (inclusive) to {@code length} (exclusive).
    20  func CheckFromToIndex(fromIndex, toIndex, length int) int {
    21  	return preconditions.CheckFromToIndex(fromIndex, toIndex, length)
    22  }
    23  
    24  // Checks if the sub-range from {@code fromIndex} (inclusive) to
    25  // {@code fromIndex + size} (exclusive) is within the bounds of range from
    26  // {@code 0} (inclusive) to {@code length} (exclusive).
    27  func CheckFromIndexSize(fromIndex, size, length int) int {
    28  	return preconditions.CheckFromIndexSize(fromIndex, size, length)
    29  }