Comments (4)
Isn't this just array_values with extra steps?
from php-src.
I need todo array_values after the ksort, this could be in the ksort function to speed up
from php-src.
Do your arrays even need sorting? Because your example already is...
Adding a flag that only makes sense to some of the sorting functions but not others is unusual, so I'm looking at what your alternatives are.
What about array_multisort, which can sort by the keys and also renumber the array?
array_multisort(array_keys($array), SORT_NATURAL, $array);
this could be in the ksort function to speed up
That's not necessarily going to be true. ksort() won't know what element should be at [0]
until it's finished sorting the entire array. So how does sorting-with-reindexing work, like regular sort()? By the looks of it, at the end of the sorting, it does something very similar to what array_values does: create a new array and copy the items into it. Thus I would expect the performance of ksort-with-renumbering and ksort+array_values to be about the same.
There's also something to be said about the simplicity of seeing both ksort and array_values explicitly written out and called in code, instead of that behavior being controlled by a special flag that adds (yet another) nuanced sorting behavior to these functions, but that's a different conversation.
Do you still feel that ksort, and I assume the other key-based and associative sorting functions as well, should have a "sort with reindexing" flag?
from php-src.
I though it could speed up, if that isn't the case, ok. I use hardcoded array keys to solve a big where, which need to start at zero, then 1, then 2, then the rest. I will use array_values which should be fast for small arrays.
I didnt know about the multisort, will look into it, but probably is the same speed.
from php-src.
Related Issues (20)
- Reproducible crash in PHP 8.4 with JIT and Excimer HOT 5
- make test always failed that displays "session.sid_length INI setting is deprecated" on macOS HOT 2
- Memory Leak in xmlCreateIntSubset HOT 6
- Configure error grep illegal option q
- Help, I use crypto asymmetric encryption symmetric key, passed to PHP there is an error! HOT 4
- stream_get_contents/fread timeouts HOT 3
- Allow to build apache2 SAPI same time with other SAPIs HOT 2
- Running out of memory in custom session handler's `write` function causes "Cannot call session save handler in a recursive manner" HOT 4
- Reconsider usages of `gethostbyname_r()` HOT 6
- Require `poll()` for UNIX based OSs and improve emulation for Windows HOT 2
- Build with libxml2 versions 2.9.0 to 2.9.3 fails HOT 6
- Install Redis with PECL fatal error: standard/php_random.h: No such file or directory HOT 4
- OPCache File Inclusion and Function Call Errors: Letter Shifting Issue During High Load on PHP 8.3.10 HOT 14
- Run a nightly build with AVX-512 emulation
- Integer overflow in curl_multi_select HOT 3
- Segmentation fault (access null pointer) in ext/dom/xml_common.h HOT 1
- Signed integer overflow in ext/standard/scanf.c HOT 3
- Stubs: internally modifyable properties are not @readonly HOT 3
- --disable-ipv6 during compilation produces error EAI_SYSTEM not found on php-8.3.10-src HOT 2
- Segmentation fault (access null pointer) in ext/dom/html5_serializer.c HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-src.