Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 6 of 6 for IsSortedFunc (0.23 sec)

  1. src/slices/sort_test.go

    	}
    	data := make(intPairs, n)
    
    	// random distribution
    	for i := 0; i < len(data); i++ {
    		data[i].a = rand.Intn(m)
    	}
    	if IsSortedFunc(data, intPairCmp) {
    		t.Fatalf("terrible rand.rand")
    	}
    	data.initB()
    	SortStableFunc(data, intPairCmp)
    	if !IsSortedFunc(data, intPairCmp) {
    		t.Errorf("Stable didn't sort %d ints", n)
    	}
    	if !data.inOrder(false) {
    		t.Errorf("Stable wasn't stable on %d ints", n)
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Thu May 09 19:20:55 UTC 2024
    - 9.5K bytes
    - Viewed (0)
  2. src/slices/iter_test.go

    	n, m := 1000, 100
    	data := make(intPairs, n)
    	for i := range data {
    		data[i].a = rand.IntN(m)
    	}
    	data.initB()
    
    	s := intPairs(SortedStableFunc(Values(data), intPairCmp))
    	if !IsSortedFunc(s, intPairCmp) {
    		t.Errorf("SortedStableFunc didn't sort %d ints", n)
    	}
    	if !s.inOrder(false) {
    		t.Errorf("SortedStableFunc wasn't stable on %d ints", n)
    	}
    
    	// iterVal converts a Seq2 to a Seq.
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Fri May 10 17:28:50 UTC 2024
    - 5.7K bytes
    - Viewed (0)
  3. src/sort/slice.go

    }
    
    // SliceIsSorted reports whether the slice x is sorted according to the provided less function.
    // It panics if x is not a slice.
    //
    // Note: in many situations, the newer [slices.IsSortedFunc] function is more
    // ergonomic and runs faster.
    func SliceIsSorted(x any, less func(i, j int) bool) bool {
    	rv := reflectlite.ValueOf(x)
    	n := rv.Len()
    	for i := n - 1; i > 0; i-- {
    		if less(i, i-1) {
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Tue Nov 28 16:40:32 UTC 2023
    - 1.8K bytes
    - Viewed (0)
  4. src/internal/trace/batchcursor_test.go

    	l := len(heap)
    	var removed []*batchCursor
    	for i := 0; i < l; i++ {
    		removed = append(removed, heap[0])
    		heap = heapRemove(heap, 0)
    		checkHeap(t, heap)
    	}
    	if !slices.IsSortedFunc(removed, (*batchCursor).compare) {
    		t.Fatalf("heap elements not removed in sorted order, got: %s", heapDebugString(removed))
    	}
    }
    
    func makeBatchCursor(v int64) *batchCursor {
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Fri May 17 18:48:18 UTC 2024
    - 3K bytes
    - Viewed (0)
  5. src/slices/sort.go

    	for i := len(x) - 1; i > 0; i-- {
    		if cmp.Less(x[i], x[i-1]) {
    			return false
    		}
    	}
    	return true
    }
    
    // IsSortedFunc reports whether x is sorted in ascending order, with cmp as the
    // comparison function as defined by [SortFunc].
    func IsSortedFunc[S ~[]E, E any](x S, cmp func(a, b E) int) bool {
    	for i := len(x) - 1; i > 0; i-- {
    		if cmp(x[i], x[i-1]) < 0 {
    			return false
    		}
    	}
    	return true
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Wed Feb 07 23:54:41 UTC 2024
    - 5.8K bytes
    - Viewed (0)
  6. src/slices/example_test.go

    	fmt.Println(slices.IsSorted([]int{0, 2, 1}))
    	// Output:
    	// true
    	// false
    }
    
    func ExampleIsSortedFunc() {
    	names := []string{"alice", "Bob", "VERA"}
    	isSortedInsensitive := slices.IsSortedFunc(names, func(a, b string) int {
    		return strings.Compare(strings.ToLower(a), strings.ToLower(b))
    	})
    	fmt.Println(isSortedInsensitive)
    	fmt.Println(slices.IsSorted(names))
    	// Output:
    	// true
    	// false
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Fri May 10 17:28:50 UTC 2024
    - 8.1K bytes
    - Viewed (0)
Back to top