简体   繁体   English

复制另一个矢量以获得更小的尺寸

[英]Copy another vector for a smaller size

I have 2 vectors.我有 2 个向量。 I want the second vector to copy the first vector for the size of n which is less than the length of the first vector.我希望第二个向量复制第一个向量,其大小为小于第一个向量的长度 (the second vector length should be n too) (第二个向量长度也应该是 n)

I tried doing this by a loop:我尝试通过循环执行此操作:

for (int i = 0; i < n; ++i)
{
    //secVector[i] will equal firstVector[i] and n is less than fristVector length
}

but the time complexity of this is O(n) and it takes a lot of time in large lengths, I wonder if there is any function could do this faster.但是它的时间复杂度是 O(n) 并且需要大量时间,我想知道是否有任何 function 可以更快地做到这一点。

This cannot be done with std vector.这不能用标准向量来完成。

There are immutable vectors where this can be done in logarithmic time, such as https://sinusoid.es/immer/ - this uses wide B trees and copy on write to give near-vector performance with O(1) copy and O(lg n) slice.有一些不可变的向量可以在对数时间内完成,例如https://sinusoid.es/immer/ - 这使用宽 B 树和写入时复制以提供接近向量的性能,具有 O(1) 复制和 O( lg n) 切片。

Such structures are considered exotic.这种结构被认为是异国情调的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM