1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use super::ParSplit; 15 16 impl<T> ParSplit for &[T] { len(&self) -> usize17 fn len(&self) -> usize { 18 <[T]>::len(self) 19 } 20 reduce(self, len: usize) -> Self21 fn reduce(self, len: usize) -> Self { 22 self.split_at(len).0 23 } split(self) -> (Self, Option<Self>)24 fn split(self) -> (Self, Option<Self>) { 25 let idx = self.len() >> 1; 26 let (left, right) = self.split_at(idx); 27 (left, Some(right)) 28 } 29 } 30 31 impl<'a, T> ParSplit for &'a mut [T] { len(&self) -> usize32 fn len(&self) -> usize { 33 <[T]>::len(self) 34 } 35 reduce(self, len: usize) -> Self36 fn reduce(self, len: usize) -> Self { 37 self.split_at_mut(len).0 38 } 39 split(self) -> (Self, Option<Self>)40 fn split(self) -> (Self, Option<Self>) { 41 let idx = self.len() >> 1; 42 let (left, right) = self.split_at_mut(idx); 43 (left, Some(right)) 44 } 45 } 46