Skip to content

Instantly share code, notes, and snippets.

@knowtheory
knowtheory / prettyprint.js
Created April 11, 2011 05:44
A pretty printer for Javascript objects that looks like Ruby's pp formatter. In use on Rhino, untested elsewhere.
function pp(object, depth, embedded) {
typeof(depth) == "number" || (depth = 0)
typeof(embedded) == "boolean" || (embedded = false)
var newline = false
var spacer = function(depth) { var spaces = ""; for (var i=0;i<depth;i++) { spaces += " "}; return spaces }
var pretty = ""
if ( typeof(object) == "undefined" ) { pretty += "undefined" }
else if ( typeof(object) == "boolean" ||
typeof(object) == "number" ) { pretty += object.toString() }
else if ( typeof(object) == "string" ) { pretty += "\"" + object + "\"" }
void rsort(uint64_t *a, uint64_t n, uint64_t *b)
{
uint32_t cnt[0x4001]={};
for (size_t i=0;i<n;i++) cnt[(a[i]&0x1fff)+1]++;
for (size_t i=0;i<0x2000;i++) cnt[i+1]+=cnt[i];
for (size_t i=0;i<n;i++) b[cnt[a[i]&0x1fff]++]=a[i];
std::swap(a, b);
for (size_t i=0;i<0x2000;i++) cnt[i]=0;