Questions tagged [slice]

A slice is a representation of a part of a sequence, usually defined by a reference to the underlying sequence, an index giving the starting position, a length or end position, and optionally a "stride" or "step" value. Please use the tags "object-slicing" for the slicing problem in C++ and "program-slicing" for the analysis technique.

A slice is a representation of a part of a sequence (including, but not limited to, lists, arrays and strings), usually defined by a reference to the underlying sequence, an index giving the starting position, a length or end position, and optionally a "stride" or "step" value.

Further reading:

6208 questions
2
votes
2 answers

How to check if slice interface elements have the same dynamic type?

I have the following structs and they follow this structure: A is the interface, and B, C, D are all types with interface A. I have a slice of variables args all with type with interface A, each of which can be B, C, D type specifically. I'd like to…
IsaIkari
  • 1,002
  • 16
  • 31
2
votes
1 answer

Create array reference to sub slice

I have a slice of data and want to create an array reference for a fixed-size subslice: let slice: &[u8] = &[1, 2, 3, 4, 5]; let array_ref: &[u8; 2] = &slice[..2]; Unfortunately, this doesn't work because the type of &[..2] is &[u8] instead of…
Heinzi
  • 5,793
  • 4
  • 40
  • 69
2
votes
2 answers

How to insert element at the beginning of a slice?

I have a slice: mySlice := []int{4,5,6,7} myelement := 3 I want to insert myelement at index 0 so that my output will be [3,4,5,6,7]. How can I do that?
2
votes
0 answers

Is there a function which swaps two ranges of different sizes within a slice?

Swapping ranges of equal sizes can already be done with std::ptr::swap_nonoverlapping. But what about ranges of different sizes within a Vec/slice/etc.? Does such a function exist? For example: let mut vector = vec![1, 2, 3, 4, 5, 6, 7, 8,…
2
votes
2 answers

How do I use the length of another column in Pandas as a slice argument

I am trying to remove rows from a dataframe where the first sequence of letters in the Ref column are equal to the Product column. For example, for the input: +---------+---------------+ | Product | Provision Ref | +---------+---------------+ | DVX …
Zabman
  • 117
  • 1
  • 12
2
votes
1 answer

How to convert from &str to [i8; 256]

I am working with a c api with automatically generated bindings by Bindgen. One of the property structs defined by the rust wrapper takes a [i8, 256], which needs to be a string such as "mystr" The C declaration is something like this: typedef…
2
votes
2 answers

Split/Slice large JSON sort free Unique by few columns & add additional element using jq

per Split/Slice large JSON using jq we are able to successfully slice huge input file into smaller chunk of data based on array size.. Would like to add a new json element to it with incrementing sequence number based on length of original array…
Ilan
  • 41
  • 4
2
votes
1 answer

Transposing Slice for golang

I am trying to implement it in Go.how can i transpose the result but i have a problem in my code.how can i help me. package main import ( "database/sql" "fmt" _ "github.com/go-sql-driver/mysql" ) this is function for tranpose the…
Larsiya
  • 79
  • 5
2
votes
2 answers

Multiple selection of dataframe using multiple column slices

I have a dataframe that has 10 columns, I am trying select columns 1 to 3 (first to third) and columns 5 to 8 (fifth to eighth). Is it possible to select using the iloc selector so that it can take multiple slices. The sample below can slice first…
mapperx
  • 197
  • 1
  • 2
  • 12
2
votes
3 answers

Enumerating sliced array using original indices

I need to slice an array and enumerate the values but I also need the reference to the original index because I'm doing an async operation that needs to be mapped back to the original index in the original array when complete. const array = ['foo',…
eozzy
  • 66,048
  • 104
  • 272
  • 428
2
votes
1 answer

Does Go slicing operator allocate new underlying array?

I was reading this article which explains how slices in Go are implemented under the hood: https://medium.com/swlh/golang-tips-why-pointers-to-slices-are-useful-and-how-ignoring-them-can-lead-to-tricky-bugs-cac90f72e77b At the end of the article is…
fresanov
  • 51
  • 2
2
votes
3 answers

Does slicing a string copy the underlying data?

In Rust, if I wanted read-only access to one &str across multiple contexts without copying the actual underlying data, am I correct in thinking that I just use a slice? Example let original_string = "here's a string"; let slice =…
2
votes
2 answers

How to slice or limit dynamic nested array nodejs

How to slice data in nested array? I want to use it with pagination for limit the data for display. I have try it with object key but only limit the nested array without show parent data I am trying use object key like this. The ouput is correct but…
2
votes
1 answer

how to edit/update initialState in slice redux

Hello I am working on a announcements app, and i need to update or edit one of announcements. I am stuck at this point and don't know how to solve it. const announcements = createSlice({ name: 'announcements', initialState: { …
Oleg Salo
  • 23
  • 3
2
votes
2 answers

For each ID return the earliest date from the start column and the latest date from the end column in r

I have a dataset which has multiple start dates and end dates for each Id. I would like to take the earliest date from the "startDate" column and the latest date from the endDate column. data = data.frame(ID=c(1,1,1,1,2,2,2), …
T K
  • 383
  • 1
  • 9