Skip to content

Instantly share code, notes, and snippets.

@bmyerz
bmyerz / Sentinel.java
Created February 2, 2018 17:51
An incomplete implementation of a linked list with a sentinel
public SLinkedList {
// header always points to the sentinel node; header is NEVER null
ListNode header;
public SLinkedList() {
// point to a dummy ListNode that serves as the sentinel node
// its data doesn't matter
header = new ListNode(-1);
}
void sort(int[] number)
{
PriorityQueue<Integer, Integer> p = new HeapPriorityQueue();
// insert array data into p
for (int i=0; i< number.length; i++) {
int x = number[i];
p.insert(x, x);
}
// take out in sorted order putting into the array
void sort(int[] number)
{
PriorityQueue<Integer, Integer> p = new HeapPriorityQueue();
// insert array data into p
for (int i=0; i< number.length; i++) {
p.insert(x, x);
}
// take out in sorted order putting into the array
int i = 0;
void sort(int[] number)
{
PriorityQueue<Integer, Integer> p = new HeapPriorityQueue();
// insert array data into p
for (int i=0; i< number.length; i++) {
p.insert(x, x);
}
// take out in sorted order putting into the array
int i = 0;
@bmyerz
bmyerz / inf.java
Created October 24, 2017 03:24
inf
for (int i=0; ; i++) {
}
@bmyerz
bmyerz / decomposegroupby_78b76ef
Created November 21, 2015 17:50
Decomposegroupby before and after changes
class DecomposeGroupBy(rules.Rule):
"""Convert a logical group by into a two-phase group by.
The local half of the aggregate before the shuffle step, whereas the remote
half runs after the shuffle step.
TODO: omit this optimization if the data is already shuffled, or
if the cardinality of the grouping keys is high.
"""
@bmyerz
bmyerz / gist:709bf367785ade27eaba
Last active August 29, 2015 14:25
coarse parallel running sum
blockdist = BlockDistribution[P partitions, N elements]
global int localsum[P] (blockdist); // for per-partition sums (alternatively represented as partition-private storage)
global int A[N] (blockdist); // input
global int B[N] (blockdist); // intermediate
global int C[N] (blockdist); // result
// compute running sum, within each partition
// we can only break dependences between groups of iterations with knowledge of how blockdist works
forall i in 0..N {
@bmyerz
bmyerz / symmetric vector iterator
Created June 26, 2015 21:12
Iterator for symmetric allocated vectors
template <GlobalCompletionEvent* GCE=&impl::local_gce, typename T, typename F>
void forall(GlobalAddress<aligned_vector<T>> symmetric_array, F loop_body) {
auto origin = mycore();
GCE->enroll(cores());
on_all_cores([=] {
auto num_elements = symmetric_array->vector.size();
forall_here<SyncMode::Async,GCE>( 0, num_elements, [=](int64_t start, int64_t iters) {
for (int64_t j=start; j<start+iters; j++) {
auto el = symmetric_array->vector[j];
loop_body(el);
{
'public:vulcan:edgesConnected' : [('nowGroup', 'LONG_TYPE'), ('currentTime', 'LONG_TYPE'), ('currentGroup', 'LONG_TYPE'), ('nextGroup', 'LONG_TYPE'), ('sharedParticleCount', 'LONG_TYPE')],
}