Javascript本机排序方法代码 [英] Javascript native sort method code

查看:152
本文介绍了Javascript本机排序方法代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何查看本机javascript方法的实现,特别是排序
方法。我正在寻找这个的原因我只是想知道算法使用的是什么,以及它的复杂性是什么。

Any idea how I can view the implementation of native javascript methods specifically the sort method. The reason why I am looking for this I am just wondering what the algorithm used is and what is the complexity of the same.

我在javascript中排序一个巨大的json对象而且我想知道我是否应该为自己做同样的方法。

I am sorting a huge json object in javascript and I was wondering if I should write my own mety hod for the same.

从浏览器到浏览器的实现也不同吗?

Also does the implementation differ from browser to browser?

推荐答案

看看WebKit实现: https:/ /gist.github.com/964673 。显然,它使用最小排序/选择排序。来源: http://svn.webkit.org/repository /webkit/trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

Take a look at the WebKit implementation: https://gist.github.com/964673. Apparently, it uses min sort/selection sort. From: http://svn.webkit.org/repository/webkit/trunk/Source/JavaScriptCore/runtime/ArrayPrototype.cpp

SpiderMonkey似乎确实使用了MergeSort。请参阅: http://hg.mozilla.org/mozilla -central / file / 28be8df0deb7 / js / src / jsarray.cpp

SpiderMonkey seems to indeed use MergeSort. See: http://hg.mozilla.org/mozilla-central/file/28be8df0deb7/js/src/jsarray.cpp.

这篇关于Javascript本机排序方法代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆