github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/x/list/cond.go (about)

     1  package list
     2  
     3  import "github.com/sagernet/sing/common"
     4  
     5  func (l List[T]) Size() int {
     6  	return l.len
     7  }
     8  
     9  func (l List[T]) IsEmpty() bool {
    10  	return l.len == 0
    11  }
    12  
    13  func (l *List[T]) PopBack() T {
    14  	if l.len == 0 {
    15  		return common.DefaultValue[T]()
    16  	}
    17  	entry := l.root.prev
    18  	l.remove(entry)
    19  	return entry.Value
    20  }
    21  
    22  func (l *List[T]) PopFront() T {
    23  	if l.len == 0 {
    24  		return common.DefaultValue[T]()
    25  	}
    26  	entry := l.root.next
    27  	l.remove(entry)
    28  	return entry.Value
    29  }
    30  
    31  func (l *List[T]) Array() []T {
    32  	if l.len == 0 {
    33  		return nil
    34  	}
    35  	array := make([]T, 0, l.len)
    36  	for element := l.Front(); element != nil; element = element.Next() {
    37  		array = append(array, element.Value)
    38  	}
    39  	return array
    40  }
    41  
    42  func (e *Element[T]) List() *List[T] {
    43  	return e.list
    44  }