text stringlengths 14 100k | source stringclasses 1
value | repo stringclasses 810
values | language stringclasses 13
values |
|---|---|---|---|
<|fim_suffix|>ight theme
return false;
}
return key.query_uint(L"AppsUseLightTheme", 1) == 0;
}
inline void apply_window_theme(HWND window) {
auto dark_theme_enabled = is_dark_theme_enabled();
// Use "immersive dark mode" on systems that support it.
// Changes the color of the window's title bar (light ... | fim | webview/webview | cpp |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | cpp |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | cpp |
/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including witho... | fim | webview/webview | cpp |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | cpp |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | cpp |
/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including witho... | fim | webview/webview | c |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | cpp |
<|fim_suffix|>return detail::json_parse_c(s, sz, key, keysz, value, valuesz);
}
WEBVIEW_DEPRECATED_PRIVATE
inline std::string json_escape(const std::string &s) {
return detail::json_escape(s);
}
WEBVIEW_DEPRECATED_PRIVATE
inline int json_unescape(const char *s, size_t n, char *out) {
return detail::json_unescape(... | fim | webview/webview | cpp |
<|fim_suffix|>ined, the defaults are as follows:
*
* - @c inline when compiling C++ code.
* - @c extern when compiling C code.
*
* The following macros can be used to automatically set an appropriate
* value for @c WEBVIEW_API:
*
* - Define @c WEBVIEW_BUILD_SHARED when building a shared library.
* - Define @c ... | fim | webview/webview | c |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | c |
<|fim_suffix|> above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTI... | fim | webview/webview | cpp |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, i... | fim | webview/webview | c |
<|fim_suffix|>h"
#endif // WEBVIEW_H
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2017 Serge Zaitsev
* Copyright (c) 2022 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* ... | fim | webview/webview | c |
<|fim_prefix|>/**
* @fil<|fim_suffix|>as `#include "webview.h"`.
*/
#ifndef WEBVIEW_ROOT_H
#define WEBVIEW_ROOT_H
#include "webview/webview.h"
#endif // WEBVIEW_ROOT_H
<|fim_middle|>e webview.h
*
* @deprecated This header file is deprecated. Use `webview/webview.h` instead.
*
* This file is provided for backwa... | fim | webview/webview | c |
<|fim_prefix|><|fim_suffix|>webview.h"
<|fim_middle|>#include "webview/<|endoftext|> | fim | webview/webview | cpp |
<|fim_prefix|>#include "webview/test_driver.hh"
#define WEBVIEW_VERSION_MAJOR 1
#define WEBVIEW_VERSION_MINOR 2
#define WEBVIEW_VERSION_PATCH 3
#define WEBVIEW_VERSION_PRE_RELEASE "-test"
#define WEBVIEW_VERSION_BUILD_METADATA "+gaabbccd"
#include "webview/webview.h"
#include <cassert>
#include <cstdint>
// This te... | fim | webview/webview | cpp |
<|fim_suffix|>ring(2, '\0'));
}
#endif
<|fim_prefix|>#include "webview/test_driver.hh"
#include "webview/webview.h"
TEST_CASE("Ensure that JSON parsing works") {
auto J = webview::detail::json_parse;
// Valid input with expected output
REQUIRE(J(R"({"foo":"bar"})", "foo", -1) == "bar");
REQUIRE(J(R"({"foo":""}... | fim | webview/webview | cpp |
<|fim_suffix|>PSTR lpCmdLine,
int nCmdShow) {
(void)hInst;
(void)hPrevInst;
(void)lpCmdLine;
(void)nCmdShow;
#else
int main(void) {
#endif
webview_t w = webview_create(0, NULL);
webview_set_title(w, "Basic Example");
webview_set_size(w, 480, 320, WEBVIEW_HINT_NONE);
webview_set_html(w... | fim | webview/webview | c |
<|fim_suffix|>/, int /*nCmdShow*/) {
#else
int main() {
#endif
try {
webview::webview w(false, nullptr);
w.set_title("Basic Example");
w.set_size(480, 320, WEBVIEW_HINT_NONE);
w.set_html("Thanks for using webview!");
w.run();
} catch (const webview::exception &e) {
std::cerr << e.what() << '... | fim | webview/webview | cpp |
<|fim_prefix|>#include "webview/webview.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#else
#include <pthread.h>
#include <unistd.h>
#endif
// Only used to suppress warnings caused by unused parameters.
#define UNUSED(x) (void)x
typedef struct {
void *arg;
void ... | fim | webview/webview | c |
<|fim_suffix|>main() {
#endif
try {
long count = 0;
webview::webview w(true, nullptr);
w.set_title("Bind Example");
w.set_size(480, 320, WEBVIEW_HINT_NONE);
// A binding that counts up or down and immediately returns the new value.
w.bind("count", [&](const std::string &req) -> std::string {... | fim | webview/webview | cpp |
<|fim_suffix|> raise Exception("clang-format not found: {}".format(clang_format_exe))
print("Reformatting file: {}".format(file))
subprocess.check_call((resolved_clang_format_exe, "-i", file))
def main(options):
base_dir = os.getcwd() if options.base is None else options.base
output_path = os.path... | fim | webview/webview | python |
<|fim_prefix|>#include "webview_amalgamation.h"
#include <stddef.h>
int<|fim_suffix|>, NULL);
webview_destroy(w);
return 0;
}
<|fim_middle|> main(void) {
webview_t w = webview_create(0<|endoftext|> | fim | webview/webview | c |
<|fim_prefix|>#include "webview_ama<|fim_suffix|>nullptr);
return 0;
}
<|fim_middle|>lgamation.h"
int main() {
webview::webview w(false, <|endoftext|> | fim | webview/webview | cpp |
<|fim_suffix|>n.h"
<|fim_prefix|>#include "w<|fim_middle|>ebview_amalgamatio<|endoftext|> | fim | webview/webview | cpp |
<|fim_suffix|> \
} catch (const exception &) { \
did_throw = true; \
} \
REQUIRE(did_throw); ... | fim | webview/webview | cpp |
<|fim_prefix|>/*
* MIT License
*
* Copyright (c) 2024 Steffen André Langnes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the righ... | fim | webview/webview | cpp |
<|fim_prefix|>/**
* This file contains an implementation of an AVL tree. An AVL tree is a special type of binary tree
* which self balances itself to keep operations logarithmic.
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.balancedtree;
import... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* This file contains an implementation of an AVL tree. An AVL tree is a special type of binary tree
* which self balances itself to keep operations logarithmic.
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.balancedtree;
public... | fim | williamfiset/algorithms | java |
<|fim_suffix|>l.compareTo(current.value);
if (cmp < 0) {
current = current.left;
} else if (cmp > 0) {
current = current.right;
} else {
return current;
}
}
return NIL;
}
// The height of a rooted tree is the number of edges between the tree's
// root and i... | fim | williamfiset/algorithms | java |
<|fim_suffix|> t.right.priority) {
t = rightRotation(t);
t.right = remove(t.right, x);
} else {
t = leftRotation(t);
t.left = remove(t.left, x);
}
}
return t;
}
}
<|fim_prefix|>/**
* This file contains an implementation of a Treap Class. Any comparable data is all... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* This file contains an implementation of a Binary Search Tree (BST) Any comparable data is allowed
* within this tree (numbers, strings, comparable Objects, etc...). Supported operations include
* adding, removing, height, and containment checks. Furthermore, multiple tree traversal Iterators
* a... | fim | williamfiset/algorithms | java |
<|fim_prefix|>// javac -d classes -sourcepath src/main/java
// src/main/java/com/williamfiset/algorithms/datastructures/binarysearchtree/SplayTree.java
// java -cp classes com.williamfi<|fim_suffix|><BinaryTree<T>> l_r = new ArrayList<>();
l_r.add(left);
l_r.add(right);
return l_r;
}
private BinaryTre... | fim | williamfiset/algorithms | java |
<|fim_suffix|>DER,
LEVEL_ORDER
}
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.binarysearchtr<|fim_middle|>ee;
public enum TreeTraversalOrder {
PRE_ORDER,
IN_ORDER,
POST_OR<|endoftext|> | fim | williamfiset/algorithms | java |
<|fim_suffix|>s = new long[N_HASHES];
bloomFilter = new BloomFilter(mods);
// // Assuming all mods are primes each mod value will have a modular inverse
for (int i = 0; i < N_HASHES; i++) {
java.math.BigInteger mod = java.math.BigInteger.valueOf(MODS[i]);
for (int j = 0; j < PRIMES.length; j++)... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* A generic bloom filter implementation that supports any hash function(s)
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.bloomfilter;
public class BloomFilter {
// The number of bitsets. This should be proportional
// to th... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* The StringSet is a probabilistic string set data structure implemented using a bloom filter and
* positional rolling hashing techniques. This data structure can be very fast (outperforming Java
* HashSet) if you're doing queries involving all substrings of a particular string. Despite being
* pr... | fim | williamfiset/algorithms | java |
<|fim_suffix|>uilder().append("[");
for (int i = 0; i < len - 1; i++) sb.append(arr[i]).append(", ");
return sb.append(arr[len - 1]).append("]").toString();
}
public static void main(String[] args) {
IntArray ar = new IntArray(50);
ar.add(3);
ar.add(7);
ar.add(6);
ar.add(-2);
ar.so... | fim | williamfiset/algorithms | java |
<|fim_suffix|>values) {
if (values == null) throw new IllegalArgumentException("Values array cannot be null!");
N = values.length;
values[0] = 0L;
// Make a clone of the values array since we manipulate
// the array in place destroying all its original content.
tree = values.clone();
for... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* A Fenwick Tree implementation which supports range updates and point queries
*
* @author Braj65, William Fiset
*/
package com.williamfiset.algorithms.datastructures.fenwicktree;
public class FenwickTreeRangeUpdatePointQuery {
// The size of the array holding the Fenwick tree values
private... | fim | williamfiset/algorithms | java |
<|fim_suffix|>e from root list.
moveToRoot(pointer);
}
}
}
private void link(FibonacciHeapNode<E> y, FibonacciHeapNode<E> x) {
// 1 remove y from the root list of H
y.getLeft().setRight(y.getRight());
y.getRight().setLeft(y.getLeft());
y.setParent(x);
if (x.getChild() == nul... | fim | williamfiset/algorithms | java |
<|fim_suffix|>return parent;
}
public void setParent(FibonacciHeapNode<E> parent) {
this.parent = parent;
}
public FibonacciHeapNode<E> getLeft() {
return left;
}
public void setLeft(FibonacciHeapNode<E> left) {
this.left = left;
}
public FibonacciHeapNode<E> getRight() {
return righ... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* The DoubleHashingTestObject is an object to test the functionality of the hash-table implemented
* with double hashing.
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.hashtable;
import java.util.Arrays;
import java.util.Rando<... | fim | williamfiset/algorithms | java |
<|fim_suffix|>reached.
@Override
protected void adjustCapacity() {
while (!(BigInteger.valueOf(capacity).isProbablePrime(20))) {
capacity++;
}
}
}
<|fim_prefix|>/**
* An implementation of a hashtable using double hashing as a collision resolution technique.
*
* @author William Fiset, william.alex... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* An implementation of a hash-table using open addressing with linear probing as a collision
* resolution method.
*
* @author William Fiset, william.alexandre.fiset@gma<|fim_suffix|>super(capacity, loadFactor);
}
@Override
protected void setupProbing(K key) {}
@Override
protected int p... | fim | williamfiset/algorithms | java |
<|fim_suffix|>for this key it will be
// found faster. This is called lazy deletion/relocation.
if (j != -1) {
// Swap the key-value pairs of positions i and j.
keys[j] = keys[i];
values[j] = values[i];
keys[i] = TOMBSTONE;
values[i] = null... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* An implementation of a hash-table using open addressing with quadratic probing as a collision
* resolution method.
*
* <p>In this implementation we are using the following probing function: H(k, x) = h(k) + f(x) mod
* 2^n
*
* <p>Where h(k) is the hash for the given key, f(x) = (x + x^2) / 2 a... | fim | williamfiset/algorithms | java |
<|fim_suffix|>x = 0;
Iterator<Entry<K, V>> bucketIter = advanceToNextBucket();
private Iterator<Entry<K, V>> advanceToNextBucket() {
while (bucketIndex < capacity) {
if (table[bucketIndex] != null && !table[bucketIndex].isEmpty())
return table[bucketIndex].iterator();
... | fim | williamfiset/algorithms | java |
<|fim_suffix|>ode2();
}
<|fim_prefix|>/**
* Simple interface file for double hashing
*
* @author William Fiset, william.a<|fim_middle|>lexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.hashtable;
public interface SecondaryHash {
// A method for a second hash function
public int ha... | fim | williamfiset/algorithms | java |
<|fim_suffix|>rsive(KDNode<T> toSearch, KDNode<T> curr, int axis) {
// If the search fails, the point is not in the tree
if (curr == null) return false;
// If the search succeeds, the point is in the tree
if (Arrays.equals(curr.point, toSearch.point)) return true;
// Otherwise, go where the point wo... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* A doubly linked list implementation.
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.linkedlist;
import java.util.Iterator;
public class DoublyLinkedList<T> implements Iterable<T> {
private int size = 0;
private Node<T> hea... | fim | williamfiset/algorithms | java |
<|fim_suffix|>0; i < size(); i++) if (heap.get(i).equals(elem)) return true;
return false;
}
// Adds an element to the priority queue, the
// element must not be null, O(log(n))
public void add(T elem) {
if (elem == null) throw new IllegalArgumentException("Cannot add null element");
heap.add(elem... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* A min priority queue implementation using a binary heap. This implementation tracks each element
* inside the binary heap with a hashtable for quick removals.
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.datastructures.priorityqueue;
impor... | fim | williamfiset/algorithms | java |
<|fim_suffix|> minimum child below it
private int minChild(int i) {
int index = -1, from = child[i], to = Math.min(sz, from + d);
for (int j = from; j < to; j++) if (less(j, i)) index = i = j;
return index;
}
private boolean less(int i, int j) {
return heap[i].compareTo(heap[j]) < 0;
}
priva... | fim | williamfiset/algorithms | java |
<|fim_suffix|>dexedBinaryHeap(int maxSize) {
super(2, maxSize);
}
}
<|fim_prefix|>/**
* An implementation of an indexed binary heap priority queue.
*
* <p>This implementation supports arbitrary keys with comparable values. To use arbitrary keys
* (such as strings or objects) first map all your keys to the int... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* An implementation of an indexed min D-ary heap priority queue.
*
* <p>This implementation supports arbitrary keys with comparable values. To use arbitrary keys
* (such as strings or objects) first map all your keys to the integer domain [0, N) where N is the
* number of keys you have and then u... | fim | williamfiset/algorithms | java |
<|fim_suffix|>x, y)) { // Use else clause?
se.knn(k, x, y, heap);
pointQuadrant = SOUTH_EAST;
}
if (pointQuadrant == 0) {
// System.out.println("UNDEFINED QUADRANT?");
// return;
}
// Get largest radius.
double radius = heap.isEmpty() ? POSITIVE_INFINITY :... | fim | williamfiset/algorithms | java |
package com.williamfiset.algorithms.datastructures.queue;
/**
* Besides the Generics, the loss of property of size is another difference between ArrayQueue and
* IntQueue. The size of ArrayQueue is calculated by the formula, as are empty status and full
* status.
*
* <p>ArrayQueue maximum size is data.length - 1.... | fim | williamfiset/algorithms | java |
<|fim_suffix|> (size == 0) {
throw new RuntimeException("Queue is empty");
}
int val = data[front];
front = (front + 1) & mask;
size--;
return val;
}
// Example usage
public static void main(String[] args) {
IntQueue q = new IntQueue(5);
q.offer(1);
q.offer(2);
q.offer... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* A simple queue implementation with a linkedlist
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.a<|fim_suffix|>nkedQueue() {}
public LinkedQueue(T firstElem) {
offer(firstElem);
}
// Return the size of the queue
public int size() {
retur... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.queue;
/**
* @author l<|fim_suffix|> elem);
public T poll();
public T peek();
public int size();
public boolean isEmpty();
}
<|fim_middle|>iujingkun, liujkon@gmail.com
* @param <T> the type of element held int the queue
*/
public interface... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.segmenttree;
import java.util.Arrays;
/*<|fim_suffix|> product, GCD, etc.).
*
* The tree is stored bottom-up: leaves occupy indices [n, 2n) and internal
* nodes occupy [1, n). Index 0 is unused. Each internal node i is the
* combination of its child... | fim | williamfiset/algorithms | java |
<|fim_suffix|>eFn)
*/
public void rangeUpdate(int l, int r, long x) {
rangeUpdate(0, 0, n - 1, l, r, x);
}
private void rangeUpdate(int i, int tl, int tr, int l, int r, long x) {
propagate(i, tl, tr);
if (l > r) {
return;
}
if (tl == l && tr == r) {
t[i] = ruf.apply(t[i], tl, t... | fim | williamfiset/algorithms | java |
<|fim_suffix|> lazy[2 * i + 1] = sumFunction(lazy[2 * i + 1], delta);
lazy[2 * i + 2] = sumFunction(lazy[2 * i + 2], delta);
}
private void propagate1(int i, int tl, int tr) {
// Check for default value because you don't want to assign to the lazy
// value if it's the default value.
if (lazy[i] != ... | fim | williamfiset/algorithms | java |
<|fim_suffix|>System.out.println(st.rangeQuery1(3, 4)); // -1
System.out.println();
// 0, 1, 2, 3, 4
// v = {2, 1, 3, 2, 2};
st.rangeUpdate1(3, 4, 2);
System.out.println(st.rangeQuery1(0, 4)); // 1
System.out.println(st.rangeQuery1(3, 4)); // 2
System.out.println(st.rangeQuery... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* Run with: bazel run //src/main/java/com/williamfiset/algorithms/datastructures/segmenttree:MinQuerySumUpdateSegmentTree
*
* <p>Several thanks to cp-algorithms for their great article on segment trees:
* https://cp-algorithms.com/data_structures/segment_tree.html
*
* <p>NOTE: This file is still... | fim | williamfiset/algorithms | java |
<|fim_suffix|>, r) + right.sum(l, r);
}
/**
* Returns the minimum element in the half-open interval [l, r).
*
* @param l left endpoint (inclusive)
* @param r right endpoint (exclusive)
* @return the minimum value in [l, r)
*
* Time: O(log(n))
*/
public int min(int l, int r) {
propagat... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* Simple segment tree implementation that supports a few range query operations (sum, min and max)
* along with point updates on individual elements.
*
* <p>Run with: bazel run
* //src/main/java/com/williamfiset/algorithms/datastructures/segmenttree:RangeQueryPointUpdateSegmentTree
*
* <p>Sever... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* Run with: bazel run //src/main/java/com/williamfiset/algorithms/datastructures/segmenttree:SumQueryAssignUpdateSegmentTree
*
* <p>Several thanks to cp-algorithms for their great article on segment trees:
* https://cp-algorithms.com/data_structures/segment_tree.html
*
* <p>NOTE: This file is st... | fim | williamfiset/algorithms | java |
<|fim_suffix|> values array
*/
private void buildSegmentTree(int i, int tl, int tr, long[] values) {
if (tl == tr) {
t[i] = values[tl];
return;
}
int tm = (tl + tr) / 2;
buildSegmentTree(2 * i + 1, tl, tm, values);
buildSegmentTree(2 * i + 2, tm + 1, tr, values);
t[i] = sumFunc... | fim | williamfiset/algorithms | java |
<|fim_suffix|>t l, int r) {
if (l > r) {
return null;
}
propagate1(i, tl, tr);
if (tl == l && tr == r) {
return t[i];
}
int tm = (tl + tr) / 2;
// Instead of checking if [tl, tm] overlaps [l, r] and [tm+1, tr] overlaps
// [l, r], simply recurse on both segments and let the ba... | fim | williamfiset/algorithms | java |
<|fim_suffix|> for (T key : map.keySet()) sb.append(key + ", ");
sb.append("]");
return sb.toString();
}
}
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.set;
public class HSet<T> implements Iterable<T> {
private static final Object DUMMY = new Object();
private static final int DEFA... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* SkipList is a data structure that is useful for dealing with dynamic sorted data. In particular
* it gives O(log(n)) average complexity of insertion, removal, and find operations. This
* implementation has been augmented with a method for determining the index of an element in the
* SkipList. Fi... | fim | williamfiset/algorithms | java |
<|fim_suffix|>, r[i]);
}
System.out.println();
}
}
// Queries [l, r] for the operation set on this sparse table.
public long query(int l, int r) {
// Fast queries types, O(1)
if (op == Operation.MIN) {
return query(l, r, minFn);
} else if (op == Operation.MAX) {
return que... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* Min sparse table example
*
* <p>Download the code: <br>
* $ git clone https://github.com/williamfiset/algorithms
*
* <p>Run: <br>
* $ bazel run //src/main/java/com/williamfiset/algorithms/datastructures/sparsetable/examples:MinSparseTable
*
* <p>Construction complexity: O(nlogn), query comp... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.stack;
import java.util.Arrays;
import java.util.EmptyStackException;
/**
* Array-based Stack
*
* A generic stack backed by a dynamically resizing array. Starts with
* capacity 16 and doubles when full. Push, pop, and peek are all O(1)
* amortized.... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.stack;
import java.util.ArrayDeque;
import java.util.EmptyStackException;
/**
* Integer-only Stack (fixed capacity)
*
* An extremely fast and lightweight stack for primitive ints. Can outperform
* java.util.ArrayDeque by a large factor due to avoidi... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.stack;
import java.util.EmptyStackException;
import java.util.Iterator;
import java.util.LinkedList;
/**
* Linked List Stack
*
* A generic stack backed by a LinkedList. Supports iteration in LIFO order.
* All core operations (push, pop, peek) run in... | fim | williamfiset/algorithms | java |
package com.williamfiset.algorithms.datastructures.stack;
/**
* Stack Interface
*
* Defines the core operations for a last-in, first-out (LIFO) data structure.
* Implementations include array-based, linked-list-based, and primitive int variants.
*
* @author liujingkun
*/
public interface Stack<T> {
/** Retur... | fim | williamfiset/algorithms | java |
<|fim_suffix|>ted static int[] toIntArray(String s) {
if (s == null) return null;
int[] t = new int[s.length()];
for (int i = 0; i < s.length(); i++) t[i] = s.charAt(i);
return t;
}
// The suffix array construction algorithm is left undefined
// as there are multiple ways to do this.
protected ... | fim | williamfiset/algorithms | java |
<|fim_suffix|>or (i = N - 1; i >= 0; --i) sa[--c[rank[sa2[i]]]] = sa2[i];
// Compute new ranks from the sorted order. Two suffixes get the same
// rank only if both their first-half and second-half ranks match.
for (sa2[sa[0]] = r = 0, i = 1; i < N; ++i) {
if (!(rank[sa[i - 1]] == rank[sa[i]]... | fim | williamfiset/algorithms | java |
<|fim_suffix|>Integer.compare(secondHalf, other.secondHalf);
return cmp;
}
@Override
public String toString() {
return originalIndex + " -> (" + firstHalf + ", " + secondHalf + ")";
}
}
public SuffixArrayMed(String text) {
super(toIntArray(text));
}
public SuffixArrayMed(int[]... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.suffixarray;
import java.util.Arrays;
/**
* Naive Suffix Array Construction
*
* Builds a suffix array by generating all suffixes, sorting them with
* a standard comparison sort, and extracting the sorted indices.
* Simple to understand but slow for... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.datastructures.trie;
import java.util.HashMap;
import java.util.Map;
/**
* Trie (Prefix Tree)
*
* A tree-like data structure for efficient storage and retrieval of strings.
* Each node stores a character and a map of children. Supports insert, delete,
* prefix co... | fim | williamfiset/algorithms | java |
<|fim_suffix|> /** Returns true if elements p and q are in the same component. */
public boolean connected(int p, int q) {
return find(p) == find(q);
}
/** Returns the size of the component containing element p. */
public int componentSize(int p) {
return sz[find(p)];
}
/** Returns the total numb... | fim | williamfiset/algorithms | java |
<|fim_suffix|> // Generates a list of shuffled values where every number in the array
// is in the range of [0, sz)
public static List<Integer> randomUniformUniqueIntegerList(int sz) {
List<Integer> lst = new ArrayList<>(sz);
for (int i = 0; i < sz; i++) lst.add(i);
Collections.shuffle(lst);
return... | fim | williamfiset/algorithms | java |
<|fim_prefix|>// Taken from @MightyPork at:
// https://stackoverflow.com/questions/4965335/how-to-print-binary-tree-diagram
package com.williamfiset.algorithms.datastructures.utils;
import java.util.*;
public class TreePrinter {
/** Node that can be printed */
public interface PrintableNode {
// Get left ch... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.dp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
/**
* Coin Change Problem (Unbounded Knapsack Variant)
*
* Given a set of coin denominations and a target amount, find the minimum
* number of coins needed t... | fim | williamfiset/algorithms | java |
<|fim_suffix|>amic programming on a DAG
* using a topological ordering (Kahn's algorithm).
*
* <p>
* Example use-case: counting the number of ways to reach each node from a
* source.
*
* <p>
* Time Complexity: O(V + E)
* Space Complexity: O(V + E)
*/
public class DagDynamicProgramming {
// Minimal edge rep... | fim | williamfiset/algorithms | java |
<|fim_suffix|> // Insert 'b' then delete 'a' is cheaper than substituting 'a'->'b'
System.out.println(editDistance("aaaaa", "aabaa", 2, 3, 10)); // 5
}
}
<|fim_prefix|>package com.williamfiset.algorithms.dp;
/**
* Edit Distance (Levenshtein Distance) — Iterative Bottom-Up DP
*
* Computes the minimum cost to ... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.dp;
/**
* Edit Distance (Levenshtein Distance) — Top-Down Recursive with Memoization
*
* Computes the minimum cost to transform string `a` into string `b` using
* three operations, each with a configurable cost:
*
* - Insert a character into `a` (cost: insert... | fim | williamfiset/algorithms | java |
/**
* An implementation of the Josephus problem Time complexity: O(n)
*
* @author Micah Stairs
*/
package com.williamfiset.algorithms.dp;
public class JosephusProblem {
// Suppose there are n people in a circle and person
// 0 kill the k'th person, then the k'th person kills
// the 2k'th person and so on un... | fim | williamfiset/algorithms | java |
<|fim_suffix|>2};
int[] V = {5, 20, 3};
// Capacity 10: best is (w=6,v=20) + 2x(w=2,v=3) = weight 10, value 26
System.out.println("2D DP: " + unboundedKnapsack(10, W, V)); // 26
// Space-efficient: same result
System.out.println("Space-efficient: " + unboundedKnapsackSpaceEfficient(10, W... | fim | williamfiset/algorithms | java |
<|fim_suffix|>i - 1][sz - w] + v > dp[i][sz])
dp[i][sz] = dp[i - 1][sz - w] + v;
}
}
// Backtrack through the table to find which items were selected.
// Starting at dp[n][capacity], walk backwards row by row:
// - dp[i][sz] != dp[i-1][sz] → item i-1 was included, reduce capacity
... | fim | williamfiset/algorithms | java |
<|fim_suffix|>S: ABC
System.out.println("LCS: " + lcs("AXBCY", "ZAYWBC"));
// LCS: 339970
System.out.println("LCS: " + lcs("398397970", "3399917206"));
}
}
<|fim_prefix|>package com.williamfiset.algorithms.dp;
/**
* Longest Common Subsequence (LCS)
*
* Given two strings A and B, find the longest subs... | fim | williamfiset/algorithms | java |
<|fim_prefix|>/**
* This file shows you how to find the length of the longest increasing subsequence length, using
* dynamic programming. Time complexity: O(n^2)
*
* @author William Fiset, william.alexandre.fiset@gmail.com
*/
package com.williamfiset.algorithms.dp;
public class LongestIncreasingSubsequence {
p... | fim | williamfiset/algorithms | java |
<|fim_suffix|>psIterative(s2)); // 2
}
}
<|fim_prefix|>/**
* Longest Palindrome Subsequence (LPS)
*
* <p>Given a string S, find the length of the longest subsequence in S that is also a palindrome.
*
* <p>Important: A subsequence is different from a substring. Subsequences do not need to be
* contiguous. For ex... | fim | williamfiset/algorithms | java |
package com.williamfiset.algorithms.dp;
/**
* Maximum Subarray Problem (Kadane's Algorithm)
*
* Given an integer array, find the contiguous subarray with the largest sum.
* Kadane's algorithm solves this in a single pass by maintaining the best
* sum ending at the current position:
*
* sum[i] = max(arr[i], su... | fim | williamfiset/algorithms | java |
<|fim_prefix|>package com.williamfiset.algorithms.dp;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
* Minimum Weight Perfect Matching (MWPM)
*
* Given n nodes and a symmetric n x n cost matrix, the goal is to find a
* pe... | fim | williamfiset/algorithms | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.