Questions tagged [vec]

78 questions
0
votes
1 answer

Vulkan unpack uvec4 from integer

I've observed some strange behavior. I have an array of unsigned 32bit integers. I use one integer to encode 4 values, each one byte in size. I'd like to then pass such buffer to vertex shader layout (location = 0) in uvec4 coords; In order to…
alagris
  • 1,838
  • 16
  • 31
0
votes
2 answers

how to push into a vector a variable's resource but keep it alive

I got a question about how to move a variable into a vector but without destroying this variable because it has to be reused in a loop. Below shows what I mean: type Letter = char; type LetterSet = Vec; fn main() { let mut v =…
foehn
  • 431
  • 4
  • 13
0
votes
2 answers

How to send to a tokio oneshot::channel when the Sender is in a Vec?

I want to use a container to manage tokio::oneshot::Senders. I'm using a Vec, but seems that values saved in Vec are references and I need to use self, not a reference, to call it: use bytes::BytesMut; use tokio::sync::oneshot; #[derive(Clone)] pub…
Harlan Chen
  • 321
  • 5
  • 20
0
votes
1 answer

Holding a sorted array - reverse sorted inputs case

I get integers from the user (one by one) and insert into a sorted vec to its right place by running binary search and finding the insertion index. The problem is when user decides to provide a reversed sorted input (one by one) then insertion will…
Renya Karasuma
  • 1,044
  • 4
  • 11
  • 18
0
votes
1 answer

How to group the elements of a collection into all combinations of N parts?

I have encountered a problem that looks simple but is actually difficult. It appears to be a subset of a combined algorithm. is there a faster and more direct algorithm? /// split the group {v1} to {n} parts /// /// For example: /// Group(here…
Anunaki
  • 763
  • 2
  • 8
  • 18
0
votes
1 answer

Agda list last of a generic list of naturals concatenated with a list of 1

I have the function: natListLast : List ℕ → ℕ natListLast [] = 0 natListLast nats@(x ∷ xs) = v.last (v.fromList nats) When I do _ : natListLast (2 l.∷ l.[] l.++ 1 l.∷ l.[]) ≡ 1 _ = refl I don't get any error. But when I try to…
fsuna064
  • 195
  • 1
  • 7
0
votes
1 answer

Agda: proof about `Vec` `last` using `with`

I'm trying to prove the following statement vecNat : ∀ {n} (xs : Vec ℕ n) → last (xs ∷ʳ 1) ≡ 1 But I get confused the (x ∷ xs) case. vecNat5 : ∀ {n} (xs : Vec ℕ n) → last (xs ∷ʳ 1) ≡ 1 vecNat5 [] = refl vecNat5 (x ∷ xs) = {! 0!} The goal…
fsuna064
  • 195
  • 1
  • 7
0
votes
0 answers

How do I get a slice containing all but the Nth element?

I would like to get a slice of references from a vector which contains all but the Nth element. In my specific case, I would like a mutable reference to the Nth element and non-mutable references to all other elements. I've got something that works…
Chuck
  • 431
  • 4
  • 10
0
votes
0 answers

How do I push an object which implements a trait with a trait parameter into a Vec?

I am trying to push an object which implements a trait with a trait parameter into a Vec: trait IRequest {} trait IRequestHandler where T: IRequest, { fn handle(&self, request: T); } pub struct CreateTodoRequest(); impl IRequest for…
0
votes
2 answers

Is there a way to convert Armadillo vector to a string in C++?

I was wondering if there is a way to convert an Armadillo vector to a std string. For example if I have this vector: arma::vec myvec("1 2 3"); //create a vector of length 3 How can I produce: std::string mystring("1 2 3"); from it?
Cinnamon
  • 43
  • 4
0
votes
1 answer

Why can I create boxed iterator from Vec and not from array?

The code below compiles, but if the 'args' passed to the function 'f' is changed from a Vec to an array of Strings it does not. I'm trying to understand why. I assume it has something to do with the ownership rules, but I could use some…
0
votes
1 answer

I'm adding a "templated non-member function" to a .h file. Why isn't my program outputting anything after I've added the code below:

//this function is takes in two arguments, a vector of type Vec and an element of type T, and returns //the number of elements that matched the argument and were successfully removed from the vector. The //order of the other elements should stay the…
nzaw96
  • 1
0
votes
0 answers

What is the canonical way to implement methods on Vec?

I have some struct Animal. I want to implement some methods on Vec. I believe the correct way to do this is to create a new wrapper object called Animals. What is the correct object to make this wrapper, though? A struct? An enum? Something…
trexinf14s
  • 261
  • 2
  • 13
0
votes
1 answer

pretty printing a Vec with a separator

I am trying to apply join (or something similar) to a Vec in order to pretty print it. What I came up with so far is this (and this does what I want): let vec: Vec = "abcdef".chars().collect(); let sep = "-"; let vec_str: String = vec …
hiro protagonist
  • 44,693
  • 14
  • 86
  • 111
0
votes
2 answers

Collecting to a Vec vs &Vec

I have the following code-snippets (don't question the sense of them ;) ) 1. get the n-th element of a Vec recursively fn helper(n: usize, current_n: usize, current_xs: &Vec, accumulator: Option) -> Option { if current_n > n…
SleepyX667
  • 670
  • 9
  • 21