segment

package module
v0.0.0-...-c5ca508 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

Segment

操作数字区段

package main

import (
	"fmt"

	"github.com/lixiangzhong/segment"
)

func main() {
	s1 := segment.Must(1, 10, "value1")
	s2 := segment.Must(11, 20, "value1")
	s3 := segment.Must(21, 25, "value3")

	ss := segment.Merge(s1, s2, s3)
	fmt.Println(ss)
	//{1~20:value1}, {21~25:value3}

	fmt.Println(segment.Continuity(s1, s2, s3))
	//true

	fmt.Println(segment.Cover(ss, segment.Must(5, 15, "valueCover")))
	//{1~4:value1}, {5~15:valueCover}, {16~20:value1}, {21~25:value3}
}

更多例子 example/

参考 github.com/google/segment/segment

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Continuity

func Continuity[T comparable](ss ...Segment[T]) bool

Continuity 判断ss是否连续

Types

type Segment

type Segment[T comparable] struct {
	// contains filtered or unexported fields
}

func Must

func Must[T comparable](start, end int64, value T) Segment[T]

func New

func New[T comparable](start, end int64, value T) (Segment[T], error)

func (Segment[T]) End

func (s Segment[T]) End() int64

func (Segment[T]) Start

func (s Segment[T]) Start() int64

func (Segment[T]) String

func (s Segment[T]) String() string

func (Segment[T]) Value

func (s Segment[T]) Value() T

type Segments

type Segments[T comparable] []Segment[T]

func Cover

func Cover[T comparable](ss Segments[T], in Segment[T]) Segments[T]

Cover 把segment覆盖在segments中

func Merge

func Merge[T comparable](ss ...Segment[T]) Segments[T]

Merge 合并segments(如果value相同)

func (Segments[T]) String

func (ss Segments[T]) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL