function log (message)
local msg = message or ""
editor.flashNotification(msg)
print(msg)
end
git = {}
function log (message)
local msg = message or ""
editor.flashNotification(msg)
print(msg)
end
git = {}
| #ident "@(#) Object.h, Rev 2.10, 96/08/02" | |
| // | |
| // Copyright (c) 1995-1996, Sun Microsystems, Inc. | |
| // portions (c) Copyright 1988, 1989 NeXT, Inc. | |
| // All rights reserved. | |
| #ifndef _OBJC_OBJECT_H_ | |
| #define _OBJC_OBJECT_H_ | |
| #import <objc/objc.h> |
| // based on xxhash32 | |
| unsigned int hash(char *data, size_t len) | |
| { | |
| unsigned int hash; | |
| if (len < 4) { | |
| // load 3 bytes, overlapping if len < 3 | |
| static unsigned char offset1[4] = { 0,0,1,1 }; | |
| static unsigned char offset2[4] = { 0,0,0,2 }; | |
| unsigned int h = data[0] + (data[offset1[len]]<<8) + (data[offset2[len]]<<16); | |
| h = xxprime1 + h*xxprime2; |
| // NOTE Compile without fast math flags. | |
| /* | |
| This is free and unencumbered software released into the public domain. | |
| Anyone is free to copy, modify, publish, use, compile, sell, or | |
| distribute this software, either in source code form or as a compiled | |
| binary, for any purpose, commercial or non-commercial, and by any | |
| means. |
This downloads standalone MSVC compiler, linker & other tools, also headers/libraries from Windows SDK into portable folder, without installing Visual Studio. Has bare minimum components - no UWP/Store/WindowsRT stuff, just files & tools for native desktop app development.
Run py.exe portable-msvc.py and it will download output into msvc folder. By default it will download latest available MSVC & Windows SDK - currently v14.40.33807 and v10.0.26100.0.
You can list available versions with py.exe portable-msvc.py --show-versions and then pass versions you want with --msvc-version and --sdk-version arguments.
To use cl.exe/link.exe first run setup_TARGET.bat - after that PATH/INCLUDE/LIB env variables will be updated to use all the tools as usual. You can also use clang-cl.exe with these includes & libraries.
To use clang-cl.exe without running setup.bat, pass extra /winsysroot msvc argument (msvc is folder name where output is stored).
| #define STR2(x) #x | |
| #define STR(x) STR2(x) | |
| #ifdef __APPLE__ | |
| #define USTR(x) "_" STR(x) | |
| #else | |
| #define USTR(x) STR(x) | |
| #endif | |
| #ifdef _WIN32 |
| // Exact square root of a known square integer | |
| // =========================================== | |
| // This snippet contains a function `isqrt64_exact` with signature | |
| // | |
| // uint32_t isqrt64_exact(uint64_t n); | |
| // | |
| // `isqrt64_exact` computes the 32-bit square root of its unsigned 64-bit | |
| // integer input, under the assumption that that input is a perfect square. | |
| // | |
| // Compile under gcc or clang with: |
| struct Object { | |
| Key key; // The key is any piece of data that uniquely identifies the object. | |
| // ... | |
| }; | |
| struct Handle { | |
| Key key; | |
| Index index; // This caches a speculative table index for an object with the corresponding key. | |
| }; |
(Originally written as a reply to an HN submission of this article: https://www.cs.virginia.edu/~lat7h/blog/posts/434.html)
There's a simple recipe for arithmetically encoding recursive algebraic data types (in the functional programming sense) which is related to this.
What you might have seen is Goedel numbering where a finite sequence of natural numbers a_0, a_1, ..., a_n (where n isn't fixed but can vary per sequence) is mapped bijectively onto p_0^a_0 a_1^p_1 ... a_n^p_n where p_0, p_1, ... is an enumeration of the primes.
However, if you want to represent trees instead of sequences, you have a better, simpler option. The key is the existence of a bijective pairing function between N^2 and N, which you can write as <m, n> for m, n in N.
You have a lot of choices for how to construct the pairing function. But a curious fact is that there is essentially one polynomial pairing function and it's the one you saw in class when you learned that the rationals are countable: https://en.wikipedia.org/wiki/Fuet
| // This can grow a Robin Hood linear probing hash table near word-at-a-time memcpy speeds. If you're confused why I use 'keys' | |
| // to describe the hash values, it's because my favorite perspective on Robin Hood (which I learned from Paul Khuong) | |
| // is that it's just a sorted gap array which is MSB bucketed and insertion sorted per chain: | |
| // https://pvk.ca/Blog/2019/09/29/a-couple-of-probabilistic-worst-case-bounds-for-robin-hood-linear-probing/ | |
| // The more widely known "max displacement" picture of Robin Hood hashing also has strengths since the max displacement | |
| // can be stored very compactly. You can see a micro-optimized example of that here for small tables where the max displacement | |
| // can fit in 4 bits: Sub-nanosecond Searches Using Vector Instructions, https://www.youtube.com/watch?v=paxIkKBzqBU | |
| void grow(Table *table) { | |
| u64 exp = 64 - table->shift; | |
| // We grow the table downward in place by a factor of 2 (not counting the overflow area at table->end). |