Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support iter_mut() for FlatArray<'mcx, T: Sized>? #1642

Open
my-vegetable-has-exploded opened this issue Apr 8, 2024 · 6 comments
Open

Support iter_mut() for FlatArray<'mcx, T: Sized>? #1642

my-vegetable-has-exploded opened this issue Apr 8, 2024 · 6 comments

Comments

@my-vegetable-has-exploded
Copy link
Contributor

I think it is helpful to support iter_mut() for pgrx::Array.
For aggregate state including pgrx::Array , support iter_mut() for pgrx::Array will make it possible to reuse to old state.

@workingjubilee
Copy link
Member

workingjubilee commented Apr 8, 2024

@my-vegetable-has-exploded It is not possible for all T. Some T are unsized so you cannot iteratively mutate them in a sensible way.

And it is not currently possible at all for Array<'a, T> because it is an explicitly "borrowed" form, i.e. it's always effectively Array<&T>. I am working on a FlatArray<'a, T: ?Sized> which can support this, by allowing &FlatArray and &mut FlatArray.

@workingjubilee
Copy link
Member

workingjubilee commented Apr 12, 2024

@my-vegetable-has-exploded I'm curious what kind of mutation you were hoping to do, exactly? It might be better for this to be modeled via an impl Write.

@my-vegetable-has-exploded
Copy link
Contributor Author

My goal is to write a aggregate function sfunc( internal-state, next-data-values ) ---> next-internal-state. I use a fixed sized Array as part of state, and I'd like to modify elements in-place (just add, like state[i] += data[i]). In my opinion, support iter_mut() will help a lot.
Thanks @workingjubilee

@workingjubilee
Copy link
Member

Ah okay, so you want integers and floats. Sure!

@workingjubilee workingjubilee changed the title Support iter_mut() for Array? Support iter_mut() for FlatArray<'mcx, T: Sized>? Apr 13, 2024
@workingjubilee
Copy link
Member

Hm. Something that looks like "mutable iteration" of TEXT[] would require a Scan-like functionality, where you buffer the state of the current/next string, or a functionality to use the "Expanded" array repr.

@my-vegetable-has-exploded
Copy link
Contributor Author

Hm. Something that looks like "mutable iteration" of TEXT[] would require a Scan-like functionality, where you buffer the state of the current/next string, or a functionality to use the "Expanded" array repr.

Sorry, I don't quite sure the point of this paragraph. If there is anything I can do to help, please tell me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants