text stringlengths 9 39.2M | dir stringlengths 25 226 | lang stringclasses 163
values | created_date timestamp[s] | updated_date timestamp[s] | repo_name stringclasses 751
values | repo_full_name stringclasses 752
values | star int64 1.01k 183k | len_tokens int64 1 18.5M |
|---|---|---|---|---|---|---|---|---|
```go
//go:build darwin || freebsd || linux || openbsd
package aghos
import (
"fmt"
"os/user"
"strconv"
"syscall"
)
func setGroup(groupName string) (err error) {
g, err := user.LookupGroup(groupName)
if err != nil {
return fmt.Errorf("looking up group: %w", err)
}
gid, err := strconv.Atoi(g.Gid)
if err !... | /content/code_sandbox/internal/aghos/user_unix.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 247 |
```go
//go:build darwin
package aghos
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/AdguardTeam/golibs/log"
)
// preCheckActionStart performs the service start action pre-check. It warns
// user that the service should be installed into Applications directory.
func preCheckActionStart() (err error... | /content/code_sandbox/internal/aghos/service_darwin.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 183 |
```go
package aghos
import (
"bytes"
"testing"
"github.com/AdguardTeam/golibs/ioutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLargestLabeled(t *testing.T) {
const (
comm = `command-name`
nl = "\n"
)
testCases := []struct {
name string
data ... | /content/code_sandbox/internal/aghos/os_test.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 696 |
```go
//go:build windows
package aghos
// TODO(a.garipov): Think of a way to implement these. Perhaps by using
// syscall.CreateProcessAsUser or something from the golang.org/x/sys module.
func setGroup(_ string) (err error) {
return Unsupported("setgid")
}
func setUser(_ string) (err error) {
return Unsupported... | /content/code_sandbox/internal/aghos/user_windows.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 85 |
```go
package aghos
// SetGroup sets the effective group ID of the calling process.
func SetGroup(groupName string) (err error) {
return setGroup(groupName)
}
// SetUser sets the effective user ID of the calling process.
func SetUser(userName string) (err error) {
return setUser(userName)
}
``` | /content/code_sandbox/internal/aghos/user.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 67 |
```go
package aghos_test
import (
"testing"
"github.com/AdguardTeam/golibs/testutil"
)
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
``` | /content/code_sandbox/internal/aghos/aghos_test.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 44 |
```go
package aghos_test
import (
"bufio"
"io"
"path"
"testing"
"testing/fstest"
"github.com/AdguardTeam/AdGuardHome/internal/aghos"
"github.com/AdguardTeam/golibs/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestFileWalker_Walk(t *testing.T) {
const attribute =... | /content/code_sandbox/internal/aghos/filewalker_test.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,159 |
```go
//go:build darwin || freebsd || linux || openbsd
package aghos
import (
"os"
"os/signal"
"golang.org/x/sys/unix"
)
func notifyReconfigureSignal(c chan<- os.Signal) {
signal.Notify(c, unix.SIGHUP)
}
func isReconfigureSignal(sig os.Signal) (ok bool) {
return sig == unix.SIGHUP
}
func sendShutdownSignal(_... | /content/code_sandbox/internal/aghos/os_unix.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 110 |
```yaml
---
!include release.yaml
---
!include snapcraft.yaml
---
!include test.yaml
``` | /content/code_sandbox/bamboo-specs/bamboo.yaml | yaml | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 20 |
```yaml
---
'version': 2
'plan':
'project-key': 'AGH'
'key': 'AGHBSNAPSPECS'
'name': 'AdGuard Home - Build and publish release'
# Make sure to sync any changes with the branch overrides below.
'variables':
'channel': 'edge'
'dockerFrontend': 'adguard/home-js-builder:2.0'
'dockerGo': 'adguard/go-... | /content/code_sandbox/bamboo-specs/release.yaml | yaml | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,989 |
```yaml
---
'version': 2
'plan':
'project-key': 'AGH'
'key': 'AHBRTSPECS'
'name': 'AdGuard Home - Build and run tests'
'variables':
'dockerFrontend': 'adguard/home-js-builder:2.0'
'dockerGo': 'adguard/go-builder:1.22.6--1'
'channel': 'development'
'stages':
- 'Tests':
'manual': false
... | /content/code_sandbox/bamboo-specs/test.yaml | yaml | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,348 |
```yaml
---
# This part of the release build is separate from the one described in
# release.yaml, because the Snapcraft infrastructure is brittle, and timeouts
# during logins and uploads often lead to release blocking.
'version': 2
'plan':
'project-key': 'AGH'
'key': 'AGHSNAP'
'name': 'AdGuard Home - Buil... | /content/code_sandbox/bamboo-specs/snapcraft.yaml | yaml | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,567 |
```shell
#!/bin/sh
# AdGuard Home Installation Script
# Exit the script if a pipeline fails (-e), prevent accidental filename
# expansion (-f), and consider undefined variables as errors (-u).
set -e -f -u
# Function log is an echo wrapper that writes to stderr if the caller
# requested verbosity level greater than ... | /content/code_sandbox/scripts/install.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 3,895 |
```go
package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"net/textproto"
"os"
"path/filepath"
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/httphdr"
"github.com/AdguardTeam/golibs/mapsutil"
)
// upload base tr... | /content/code_sandbox/scripts/translations/upload.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 760 |
```go
package main
import (
"flag"
"fmt"
"io"
"net/http"
"net/url"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"time"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/ioutil"
"github.com/AdguardTeam/golibs/log"
)
// download and save all translations.
func (c *twoskyClient) down... | /content/code_sandbox/scripts/translations/download.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,003 |
```go
// translations downloads translations, uploads translations, prints summary
// for translations, prints unused strings.
package main
import (
"bufio"
"bytes"
"cmp"
"encoding/json"
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/... | /content/code_sandbox/scripts/translations/main.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 3,163 |
```javascript
const fs = require('fs');
const readline = require('readline');
const dnsPacket = require('dns-packet')
const processLineByLine = async (source, callback) => {
const fileStream = fs.createReadStream(source);
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infi... | /content/code_sandbox/scripts/querylog/anonymize.js | javascript | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 746 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a significant change is made to this script.
#
# AdGuard-Project-Version: 8
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '0' ]
then
set -x
fi
# Set $EXIT_ON_ERROR to zero to see... | /content/code_sandbox/scripts/make/go-lint.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 2,012 |
```shell
#!/bin/sh
# AdGuard Home Version Generation Script
#
# This script generates versions based on the current git tree state. The valid
# output formats are:
#
# * For release versions, "v0.123.4". This version should be the one in the
# current tag, and the script merely checks, that the current commit ... | /content/code_sandbox/scripts/make/version.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,468 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
dist_dir="${DIST_DIR:?please set DIST_DIR}"
sudo_cmd="${SUDO:-}"
readonly dist_dir sudo_cmd
$sudo_cmd rm -f\
./AdGuardHome\
./AdGuardHome.exe\
./coverage.txt\
;
$sudo_cmd rm -f -r\
./bin/\
./bu... | /content/code_sandbox/scripts/make/clean.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 133 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a significant change is made to this script.
#
# AdGuard-Project-Version: 1
verbose="${VERBOSE:-0}"
readonly verbose
# Verbosity levels:
# 0 = Don't print anything except for errors.
# 1 = Pr... | /content/code_sandbox/scripts/make/go-test.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 337 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a significant change is made to this script.
#
# AdGuard-Project-Version: 4
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '1' ]
then
set -x
v_flags='-v=1'
x_flags='-x=1'
elif [ ... | /content/code_sandbox/scripts/make/go-tools.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 581 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
readonly verbose
# Verbosity levels:
# 0 = Don't print anything except for errors.
# 1 = Print commands, but not nested commands.
# 2 = Print everything.
if [ "$verbose" -gt '1' ]
then
set -x
v_flags='-v=1'
x_flags='-x=1'
elif [ "$verbose" -gt '0' ]
then
set -x
v_... | /content/code_sandbox/scripts/make/go-fuzz.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 347 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a remarkable change is made to this script.
#
# AdGuard-Project-Version: 2
verbose="${VERBOSE:-0}"
readonly verbose
# Don't use -f, because we use globs in this script.
set -e -u
if [ "$verbose"... | /content/code_sandbox/scripts/make/sh-lint.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 300 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a remarkable change is made to this script.
#
# AdGuard-Project-Version: 2
verbose="${VERBOSE:-0}"
readonly verbose
set -e -f -u
if [ "$verbose" -gt '0' ]
then
set -x
fi
# NOTE: Adjust for you... | /content/code_sandbox/scripts/make/md-lint.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 123 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
debug_flags='--debug=1'
else
set +x
debug_flags='--debug=0'
fi
readonly debug_flags
set -e -f -u
# Require these to be set. The channel value is validated later.
channel="${CHANNEL:?please set CHANNEL}"
commit="${COMMIT:?please se... | /content/code_sandbox/scripts/make/build-docker.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,006 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
readonly verbose
# Verbosity levels:
# 0 = Don't print anything except for errors.
# 1 = Print commands, but not nested commands.
# 2 = Print everything.
if [ "$verbose" -gt '1' ]
then
set -x
v_flags='-v=1'
x_flags='-x=1'
elif [ "$verbose" -gt '0' ]
then
set -x
v_... | /content/code_sandbox/scripts/make/go-bench.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 302 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a significant change is made to this script.
#
# AdGuard-Project-Version: 1
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '1' ]
then
env
set -x
x_flags='-x=1'
elif [ "$verbose" ... | /content/code_sandbox/scripts/make/go-deps.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 152 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a remarkable change is made to this script.
#
# AdGuard-Project-Version: 5
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '0' ]
then
set -x
fi
# Set $EXIT_ON_ERROR to zero to see ... | /content/code_sandbox/scripts/make/txt-lint.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 558 |
```shell
#!/bin/sh
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a significant change is made to this script.
#
# AdGuard-Project-Version: 2
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '1' ]
then
env
set -x
x_flags='-x=1'
elif [ "$verbose" ... | /content/code_sandbox/scripts/make/go-upd-tools.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 164 |
```shell
#!/bin/sh
# Common script helpers
#
# This file contains common script helpers. It should be sourced in scripts
# right after the initial environment processing.
# This comment is used to simplify checking local copies of the script. Bump
# this number every time a remarkable change is made to this script.... | /content/code_sandbox/scripts/make/helper.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 460 |
```shell
#!/bin/sh
# AdGuard Home Release Script
#
# The commentary in this file is written with the assumption that the reader
# only has superficial knowledge of the POSIX shell language and alike.
# Experienced readers may find it overly verbose.
# The default verbosity level is 0. Show log messages if the caller... | /content/code_sandbox/scripts/make/build-release.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 2,889 |
```shell
#!/bin/sh
# AdGuard Home Build Script
#
# The commentary in this file is written with the assumption that the reader
# only has superficial knowledge of the POSIX shell language and alike.
# Experienced readers may find it overly verbose.
# This comment is used to simplify checking local copies of the script... | /content/code_sandbox/scripts/make/go-build.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,056 |
```unknown
#!/bin/sh
set -e -f -u
# This comment is used to simplify checking local copies of the script.
# Bump this number every time a significant change is made to this
# script.
#
# AdGuard-Project-Version: 3
# TODO(a.garipov): Add pre-merge-commit.
# Only show interactive prompts if there a terminal is attach... | /content/code_sandbox/scripts/hooks/pre-commit | unknown | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 794 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
# Function log is an echo wrapper that writes to stderr if the caller requested
# verbosity level greater than 0. Otherwise, it does nothing.
log() {
if [ "$verbose" -gt '0' ]
then
# Don't use quotes to get word s... | /content/code_sandbox/scripts/snap/upload.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 566 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
channel="${CHANNEL:?please set CHANNEL}"
readonly channel
printf '%s %s\n'\
'386' 'i386'\
'amd64' 'amd64'\
'armv7' 'armhf'\
'arm64' 'arm64' \
| while read -r arch snap_arch
do
release_url="path_to_url{channel}/... | /content/code_sandbox/scripts/snap/download.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 199 |
```shell
#!/bin/sh
verbose="${VERBOSE:-0}"
if [ "$verbose" -gt '0' ]
then
set -x
fi
set -e -f -u
# Function log is an echo wrapper that writes to stderr if the caller requested
# verbosity level greater than 0. Otherwise, it does nothing.
#
# TODO(a.garipov): Add to helpers.sh and use more actively in scripts.
lo... | /content/code_sandbox/scripts/snap/build.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 534 |
```go
// vetted-filters fetches the most recent Hostlists Registry filtering rule list
// index and transforms the filters from it to AdGuard Home's format.
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"log/slog"
"net/http"
"net/url"
"os"
"time"
"github.com/AdguardTeam/golibs/logutil/slogut... | /content/code_sandbox/scripts/vetted-filters/main.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 1,211 |
```go
// blocked services fetches the most recent Hostlists Registry blocked service
// index and transforms the filters from it to AdGuard Home's data and code
// formats.
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"os"
"slices"
"strings"
"text/template"
"time"
"github.com/AdguardTeam... | /content/code_sandbox/scripts/blocked-services/main.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 870 |
```shell
#!/bin/sh
set -e -f -u -x
# This script syncs companies DB that we bundle with AdGuard Home. The source
# for this database is path_to_url
#
trackers_url='path_to_url
output='./client/src/helpers/trackers/trackers.json'
readonly trackers_url output
curl -o "$output" -v "$trackers_url"
``` | /content/code_sandbox/scripts/companiesdb/download.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 83 |
```unknown
# A docker file for scripts/make/build-docker.sh.
FROM alpine:3.18
ARG BUILD_DATE
ARG VERSION
ARG VCS_REF
LABEL\
maintainer="AdGuard Team <devteam@adguard.com>" \
org.opencontainers.image.authors="AdGuard Team <devteam@adguard.com>" \
org.opencontainers.image.created=$BUILD_DATE \
org.opencontainers.i... | /content/code_sandbox/docker/Dockerfile | unknown | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 579 |
```yaml
# The %VARIABLES% are be replaced by actual values by the build script.
'name': 'adguard-home'
'base': 'core22'
'version': '%VERSION%'
'summary': Network-wide ads & trackers blocking DNS server
'description': |
AdGuard Home is a network-wide software for blocking ads & tracking. After
you set it up, it'll ... | /content/code_sandbox/snap/snap.tmpl.yaml | yaml | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 390 |
```desktop
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=AdGuard Home
Comment=Network-wide ads & trackers blocking DNS server
Exec=adguard-home.adguard-home-web
Icon=${SNAP}/meta/gui/adguard-home-web.png
Terminal=false
``` | /content/code_sandbox/snap/gui/adguard-home-web.desktop | desktop | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 57 |
```shell
#!/bin/sh
conf_file="${SNAP_DATA}/AdGuardHome.yaml"
readonly conf_file
if ! [ -f "$conf_file" ]
then
xdg-open 'path_to_url
exit
fi
# Get the admin interface port from the configuration.
awk_prog='/^[^[:space:]]/ { is_http = /^http:/ };/^[[:space:]]+address:/ { if (is_http) print $2 }'
readonly awk_prog... | /content/code_sandbox/snap/local/adguard-home-web.sh | shell | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 163 |
```go
// Code generated by go run ./scripts/blocked-services/main.go; DO NOT EDIT.
package filtering
// blockedService represents a single blocked service.
type blockedService struct {
ID string `json:"id"`
Name string `json:"name"`
IconSVG []byte `json:"icon_svg"`
Rules []string `json:"rules"`
}
... | /content/code_sandbox/internal/filtering/servicelist.go | go | 2016-07-06T10:31:47 | 2024-08-16T18:17:06 | AdGuardHome | AdguardTeam/AdGuardHome | 24,082 | 122,024 |
```java
package data_structures;
import java.util.Arrays;
public class MoAlgorithm {
// Queries: Given L and R, find the number of distinct values in [L, R]
static int ans; // answer of the current range
static int[] count; // count[i] = frequency of value i in the current range
static void add(int val)
... | /content/code_sandbox/data_structures/MoAlgorithm.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 387 |
```java
package data_structures;
public class SQRT_Decomposition {
// Query Type: find sum of subarray [L, R]
static int[] preprocess(int[] a, int n)
{
int s = (int) Math.sqrt(n) + 1;
int[] b = new int[(n + s - 1)/ s];
for(int i = 0; i < n; ++i)
b[i / s] += a[i];
return b;
}
static int query(int[]... | /content/code_sandbox/data_structures/SQRT_Decomposition.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 282 |
```java
package data_structures;
import java.util.Random;
// TODO Needs Testing
public class TreapSet <K extends Comparable<K>>
{
class Node<T extends Comparable<T>>
{
T key;
Node<T> left, right;
int prior, size;
Node(T k, int p, int s, Node<T> l, Node<T> r)
{
key = k;
prior = p;
size = s;
l... | /content/code_sandbox/data_structures/TreapSet.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 994 |
```java
package data_structures;
import java.util.Random;
//0- based indexable skip list.
public class IndexableSkipList <E extends Comparable<E>> {
class Node
{
E value;
int level;
int length;
Node next;
Node down;
public Node(E val, int lvl, int ps, Node nxt, Node dwn)
{
value = val;
leve... | /content/code_sandbox/data_structures/IndexableSkipList.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,235 |
```java
package data_structures;
import java.util.*;
public class SkipList <T extends Comparable<T>>
{
class Node
{
Node next, down;
int level;
T value;
public Node(T v, int l, Node n, Node d)
{
value = v;
level = l;
next = n;
down = d;
}
}
Node head;
R... | /content/code_sandbox/data_structures/SkipList.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 510 |
```java
package data_structures;
//Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
public class UnionFind {
int[] p, rank, setSize;
int numSets;
public UnionFind(int N)
{
p = new int[numSets = N];
r... | /content/code_sandbox/data_structures/UnionFind.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 311 |
```java
package data_structures;
// static Range Minimum Query, DP Solution
public class SparseTable {
int A[], SpT[][];
SparseTable(int[] A)
{
int n = A.length; this.A = A;
int k = (int)Math.floor(Math.log(n) / Math.log(2)) + 1;
SpT = new int[n][k];
for (... | /content/code_sandbox/data_structures/SparseTable.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 413 |
```java
package data_structures.sortings;
public class MergeSort
{
/*
* - Complexity O(n log n)
* - Stable sort algorithm
* - Can be used to compute inversion index
*/
static final int INF = Integer.MAX_VALUE;
static void mergeSort(int[] a, int b, int e)
{
if(b < e)
{
int q = (b + e) / 2;
merge... | /content/code_sandbox/data_structures/sortings/MergeSort.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 320 |
```java
package data_structures.linear;
public class Bitmask {
static int setBit(int S, int j) { return S | 1 << j; }
static int clearBit(int S, int j) { return S & ~(1 << j); }
static int toggleBit(int S, int j) { return S ^ 1 << j; }
static boolean isOn(int S, int j) { return (S & 1 << j) != 0; }
static in... | /content/code_sandbox/data_structures/linear/Bitmask.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 274 |
```java
package data_structures.trees;
import java.util.Scanner;
// Range Sum Query (with lazy propagation)
public class SegmentTree { // 1-based DS, OOP
int N; //the number of elements in the array as a power of 2 (i.e. after padding)
int[] array, sTree, lazy;
SegmentTree(int[] in)
{
array = in; N =... | /content/code_sandbox/data_structures/trees/SegmentTree.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 856 |
```java
package data_structures;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class HLD {
//1.Take input and processing(precomputation + query)
static int N, nodeVal[]; //input
static ArrayList<Integer>[] adjList; //input
@SuppressWarnings("unchecked")
public static... | /content/code_sandbox/data_structures/HLD.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,812 |
```java
package data_structures.trees;
public class PersistentSegmentTree {
class Node
{
Node left, right; int sum;
Node(int x) { sum = x; }
Node(Node left, Node right)
{
this.left = left;
this.right = right;
if(left != null)
... | /content/code_sandbox/data_structures/trees/PersistentSegmentTree.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 384 |
```java
package data_structures.trees;
public class FenwickTree { // one-based DS
int n;
int[] ft;
FenwickTree(int size) { n = size; ft = new int[n+1]; }
int rsq(int b) //O(log n)
{
int sum = 0;
while(b > 0) { sum += ft[b]; b -= b & -b;} //min?
return sum;
}
int rsq(int a, int b) { return rsq(b) -... | /content/code_sandbox/data_structures/trees/FenwickTree.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 445 |
```java
package data_structures.trees;
public class SegmentTree2D { // subrectangle sum, point update
int[][] matrix;
int[][] tree;
int N, M;
SegmentTree2D(int[][] a)
{
matrix = a;
N = 1; while(N < a.length) N <<= 1;
M = 1; while(M < a[0].length) M <<= 1;
build... | /content/code_sandbox/data_structures/trees/SegmentTree2D.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,099 |
```java
package other_algorithms;
public class Shuffle {
static void shuffle(int[] a)
{
int n = a.length;
for(int i = 0; i < n; i++)
{
int r = i + (int)(Math.random() * (n - i));
int tmp = a[i];
a[i] = a[r];
a[r] = tmp;
}
}
}
``` | /content/code_sandbox/other_algorithms/Shuffle.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 89 |
```java
package other_algorithms;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Stack;
/*
* Longest Increasing Subsequence - O(n log n) solution
*
* Main Variables
* ==============
* - A is the original array containing elements for which we need to find LIS
* - L is built incremen... | /content/code_sandbox/other_algorithms/LIS.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 573 |
```java
package data_structures.trees;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class QuadTree {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int N = (int) Math.pow(2, Math.ceil(Math.lo... | /content/code_sandbox/data_structures/trees/QuadTree.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,532 |
```java
package other_algorithms;
/*
* Convex Hull Optimization
* dp[i] = min(j < i){ dp[j] + a[i] * b[j] } where b[j] >= b[j + 1]
*
* Original Complexity: O(n^2)
* Optimized Complexity: O(n log n) or O(n) if a[i] <= a[i + 1]
*
* Following operations are used within the DP function
*
* Can be trapped in ov... | /content/code_sandbox/other_algorithms/ConvexHullOptimization1.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 500 |
```java
package other_algorithms;
/*
* Convex Hull Optimization
* dp[i] = min(j < i){ dp[j] + a[i] * b[j] } where b[j] >= b[j + 1]
*
* Original Complexity: O(n^2)
* Optimized Complexity: O(n log n) or O(n) if a[i] <= a[i + 1]
*
* Following operations are used within the DP function
*
* Overflow avoided ass... | /content/code_sandbox/other_algorithms/ConvexHullOptimization2.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 325 |
```java
package other_algorithms;
public class Precomputation {
//1. Precompute the number of ones in a given number
static int[] bitCount;
static void pre(int n)
{
bitCount = new int[1<<n];
for(int i = 0; i < n; i++)
bitCount[1<<i] = 1;
for(int i = 1; i < 1<<n; i++)
{
bitCount[i] = 1 + bitCount[i ... | /content/code_sandbox/other_algorithms/Precomputation.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 229 |
```java
package other_algorithms;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Scanner
{
StringTokenizer st;
BufferedReader br;
public Scanner(InputStream s){ br = new BufferedReader(new InputStrea... | /content/code_sandbox/other_algorithms/Scanner.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 329 |
```java
package geometry;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import java.util.TreeSet;
public class LineSweep
{
static final double EPS = 1e-9;
public static void main(String[] args) throws NumberFormatException, IOException
{
Scanner sc... | /content/code_sandbox/geometry/LineSweep.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 466 |
```java
package geometry;
public class Line {
static final double INF = 1e9, EPS = 1e-9;
double a, b, c;
Line(Point p, Point q)
{
if(Math.abs(p.x - q.x) < EPS) { a = 1; b = 0; c = -p.x; }
else
{
a = (p.y - q.y) / (q.x - p.x);
b = 1.0;
c = -(a * p.x + p.y);
}
}
Line(Point p, double m... | /content/code_sandbox/geometry/Line.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 368 |
```java
package geometry;
public class LineSegment {
Point p, q;
LineSegment(Point a, Point b) { p = a; q = b; }
boolean intersect(LineSegment ls)
{
Line l1 = new Line(p, q), l2 = new Line(ls.p, ls.q);
if(l1.parallel(l2))
{
if(l1.same(l2))
return p.between(ls.p, ls.q) || q.between(ls.p, ls.q) ||... | /content/code_sandbox/geometry/LineSegment.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 158 |
```java
package geometry;
public class Geometry {
static final double INF = 1e9, EPS = 1e-9; // better use 1e-11 for large coordinates and 1e-15 if infinite precision is required
static double degToRad(double d) { return d * Math.PI / 180.0; }
static double radToDeg(double r) { return r * 180.0 / Math.PI; }
... | /content/code_sandbox/geometry/Geometry.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 357 |
```java
package geometry;
import java.util.Arrays;
public class Polygon {
// Cases to handle: collinear points, polygons with n < 3
static final double EPS = 1e-9;
Point[] g; //first point = last point, counter-clockwise representation
Polygon(Point[] o) { g = o; }
double perimeter()
{
double sum = ... | /content/code_sandbox/geometry/Polygon.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,212 |
```java
package geometry;
public class Triangle {
static final double EPS = 1e-9;
Point a, b, c;
double ab, bc, ca;
Triangle(Point p, Point q, Point r) //counter clockwise
{
a = p;
if(Point.ccw(p, q, r)) { b = q; c = r; }
else { b = r; c = q; }
ab = a.dist(b); bc = b.dist(c); ca = c.dist(a);
}
dou... | /content/code_sandbox/geometry/Triangle.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 862 |
```java
package geometry;
public class Circle { //equation: (x-c.x)^2 + (y-c.y)^2 = r^2
static final double EPS = 1e-9;
Point c;
double r;
Circle(Point p, double k) { c = p; r = k; }
int inside(Point p) //1 for inside, 0 for border, -1 for outside
{
double d = p.dist(c);
return d + EPS < r ? 1 : Math.... | /content/code_sandbox/geometry/Circle.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 777 |
```java
package geometry;
public class Point implements Comparable<Point>{
static final double EPS = 1e-9;
double x, y;
Point(double a, double b) { x = a; y = b; }
public int compareTo(Point p)
{
if(Math.abs(x - p.x) > EPS) return x > p.x ? 1 : -1;
if(Math.abs(y - p.y) > EPS) return y... | /content/code_sandbox/geometry/Point.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,009 |
```java
package geometry;
public class Vector {
double x, y;
Vector(double a, double b) { x = a; y = b; }
Vector(Point a, Point b) { this(b.x - a.x, b.y - a.y); }
Vector scale(double s) { return new Vector(x * s, y * s); } //s is a non-negative value
double dot(Vector v) { return (x * v.x + y *... | /content/code_sandbox/geometry/Vector.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 174 |
```java
package geometry;
public class Rectangle {
static final double EPS = 1e-9;
Point ll, ur;
Rectangle(Point a, Point b) { ll = a; ur = b; }
double area() { return (ur.x - ll.x) * (ur.y - ll.y); }
boolean contains(Point p)
{
return p.x <= ur.x + EPS && p.x + EPS >= ll.x && p.y <= ur.y + EPS && p.y + ... | /content/code_sandbox/geometry/Rectangle.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 226 |
```java
package math;
public class Polynomial {
static final double EPS = 1e-9;
int degree, coeffs[];
Polynomial(int[] c) { degree = c.length - 1; coeffs = c; }
double evaluate(double x) // O(degree)
{
double res = 0.0;
for(int i = degree; i >= 0; --i)
res = res * x + coeffs[i];
return res;
}
... | /content/code_sandbox/math/Polynomial.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 295 |
```java
package math;
import java.util.ArrayList;
import java.util.Collections;
public class Permutations {
/*
* 1. Compute Next Permutation
*/
static boolean nextPermutation(char[] c)
{
// 1. finds the largest k, that c[k] < c[k+1]
int first = getFirst(c);
if(first == -1)
return false;
// 2. fin... | /content/code_sandbox/math/Permutations.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 757 |
```java
package math;
public class Exponentiation {
/*
* 1. Binary Exponentiation
*/
static int pow(int a, int e) // O(log e)
{
int res = 1;
while(e > 0)
{
if((e & 1) == 1)
res *= a;
a *= a;
e >>= 1;
}
return res;
}
/*
* 2. Fast Exponentiation
*/
static int modPow(int a, int e,... | /content/code_sandbox/math/Exponentiation.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 650 |
```java
package math;
import java.math.BigInteger;
public class NewtonMethod {
/*
* Newton's Method: Xn+1 = Xn - f(Xn) / f'(Xn)
* Purpose: Find roots of a real-valued function, i.e. solve f(x) = 0
*/
static final double EPS = 1e-15;
/*
* 1. Find square root of n
*/
static double sqrt(double n)
{
... | /content/code_sandbox/math/NewtonMethod.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 391 |
```java
package math.game_theory;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
/*
* Algorithm for finding winning, losing and draw positions in games
* that can represented by a directed graph (possibly with cycles)
*/
public class GamesOnGeneralGraphs {
static boolean[] win, ... | /content/code_sandbox/math/game_theory/GamesOnGeneralGraphs.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 295 |
```java
package math.game_theory;
import java.util.ArrayList;
/*
* Example on Games on General Graphs (path_to_url
*/
public class PoliceAndThief {
static final int[] dx = new int[] {0, 0, 0, -1, 1, -1, 1, -1, 1};
static final int[] dy = new int[] {0, -1, 1, 0, 0, -1, 1, 1, -1};
static final int POLICE = 0, TH... | /content/code_sandbox/math/game_theory/PoliceAndThief.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 756 |
```java
package math.number_theory;
public class ExtendedEuclid {
/*
* Extended Euclid Algorithm for Solving Linear Diophantine Equation
* Solve: ax + by = c. Let d = gcd(a, b).
* If d | c, then it has infinite number of solutions. Otherwise, it has no solution.
*
* The solution derived is one of the mini... | /content/code_sandbox/math/number_theory/ExtendedEuclid.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 281 |
```java
package math.number_theory;
import java.util.ArrayList;
public class PrimeFactorization {
static ArrayList<Integer> primes; // generated by sieve
/*
* 1. Generating a list of prime factors of N
*/
static ArrayList<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N))
{
ArrayList<Integer> f... | /content/code_sandbox/math/number_theory/PrimeFactorization.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 542 |
```java
package math.number_theory;
import java.util.ArrayList;
public class PrimeNumbers {
/*
* 1. Sieve of Eratosthenes: generate all primes in [2, N]
*/
static ArrayList<Integer> primes;
static int[] isComposite;
static void sieve(int N) // O(N log log N)
{
isComposite = new int[N+1];
isCompos... | /content/code_sandbox/math/number_theory/PrimeNumbers.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 543 |
```java
package math.combinatorics;
public class Fibonacci {
static int fib[];
static int fibonacci(int n) //O(log n)
{
if (n == 0)
return 0;
if (n <= 2)
return 1;
if (fib[n] != -1)
return fib[n];
int k = n >> 1;
int a = fibonacci(k), b = fibonacci(k+1);
if (n%2 == 0)
return fib[n... | /content/code_sandbox/math/combinatorics/Fibonacci.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 142 |
```java
package math.number_theory;
import java.util.Arrays;
public class ModifiedSieve {
/*
* 1. Modified sieve for number of prime factors
*/
static void numPF(int N)
{
int[] pf = new int[N];
for(int i = 2; i < N; ++i)
if(pf[i] == 0)
for(int j = i; j < N; j += i)
{
int p = 0, k = j;
... | /content/code_sandbox/math/number_theory/ModifiedSieve.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 421 |
```java
package math.combinatorics;
import java.util.ArrayList;
import java.util.Arrays;
public class InclusionExclusionPrinciple {
/*
* 1. Count the number of numbers in the range [1, r] that are coprime with n
*/
static int countCoprime(int n, int r) // O(sqrt(n))
{
ArrayList<Integer> primes = new Arra... | /content/code_sandbox/math/combinatorics/InclusionExclusionPrinciple.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 633 |
```java
package math.combinatorics;
public class BinomialCoefficient {
/*
* 1. Pascal's Rule: recursive | Top-down approach
*/
static long[][] comb; //may need BigInteger, if the numbers are large, use a treemap
static long nCr1(int n , int k)
{
if(n < k)
return 0;
if(k == 0 || k == n)
return 1;... | /content/code_sandbox/math/combinatorics/BinomialCoefficient.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 573 |
```java
package graphs.mst;
import java.util.ArrayList;
import java.util.PriorityQueue;
public class MST_Prim {
static ArrayList<Edge>[] adjList;
static int V;
static int prim() //O(E log E)
{
int mst = 0;
boolean[] visited = new boolean[V];
PriorityQueue<Edge> pq = new PriorityQueue<Edge>();
pq.add(n... | /content/code_sandbox/graphs/mst/MST_Prim.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 228 |
```java
package graphs.mst;
import java.util.Arrays;
public class MST_Kruskal {
static Edge[] edgeList;
static int V;
static int kruskal() //O(E log E)
{
int mst = 0;
Arrays.sort(edgeList);
UnionFind uf = new UnionFind(V);
for(Edge e: edgeList)
if(uf.union(e.u, e.v))
mst += e.w;
return mst;
... | /content/code_sandbox/graphs/mst/MST_Kruskal.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 359 |
```java
package graphs.traversal;
import java.util.ArrayList;
/*
* Articulation Points and Bridges in Undirected Graphs - Tarjan's Algorithm (DFS Variant)
*/
public class ArticulationPointsAndBridges {
static ArrayList<Integer>[] adjList;
static int[] dfs_low, dfs_num, parent;
static int V, counter, root, rootC... | /content/code_sandbox/graphs/traversal/ArticulationPointsAndBridges.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 343 |
```java
package graphs.traversal;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class GraphTraversal {
static final int VISITED = 2, EXPLORED = 1, UNVISITED = 0;
static ArrayList<Integer>[] adjList;
static boolean[] visited, adjMat[];
static int V... | /content/code_sandbox/graphs/traversal/GraphTraversal.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 1,205 |
```java
package graphs.traversal;
import java.util.ArrayList;
import java.util.Stack;
public class BridgeTree {
static ArrayList<Integer>[] adjList, tree;
static Stack<Integer> stack;
static int[] dfs_low, dfs_num, bridgeComp;
static int V, counter;
static void bridgeTree()
{
counter = 0;
dfs_low = new i... | /content/code_sandbox/graphs/traversal/BridgeTree.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 411 |
```java
package graphs.traversal;
import java.util.ArrayList;
import java.util.Stack;
/*
* Strongly Connected Components (Directed Graphs) - Tarjan's Algorithm (DFS Variant)
*/
public class StronglyConnectedComponents1 {
static ArrayList<Integer>[] adjList;
static int V, counter, SCC, dfs_num[], dfs_low[];
stat... | /content/code_sandbox/graphs/traversal/StronglyConnectedComponents1.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 294 |
```java
package graphs.traversal;
import java.util.ArrayList;
import java.util.Stack;
// Kosaraju's Algorithm: Finding Strongly Connected Components of a directed graph
public class KosarajuAlgorithm {
static int N;
static ArrayList<Integer>[] adjList, adjListR, graph;
static Stack<Integer> stack;
static boole... | /content/code_sandbox/graphs/traversal/KosarajuAlgorithm.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 277 |
```java
package graphs.traversal;
import java.util.ArrayList;
public class BridgesOnline {
/*
* WARNING: NOT TESTED BEFORE
*
* - A block is a set of connected nodes with no bridges.
* - A Component is a set of connected nodes possibly bridges.
* It consists of several blocks forming a tree (bridge tree)... | /content/code_sandbox/graphs/traversal/BridgesOnline.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 908 |
```java
package graphs.traversal;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;
/*
* Biconnected Components
*/
public class BiconnectedComponents {
static ArrayList<Integer>[] adjList, inBiComp;
static int[] dfs_low, dfs_num;
static int V, counter, biCompIdx;
static Stack<Intege... | /content/code_sandbox/graphs/traversal/BiconnectedComponents.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 573 |
```java
package graphs.special;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.ListIterator;
/*
* Printing Euler Tour in an Eulerian Graph
*/
public class EulerTour {
static class Edge
{
int node;
boolean used;
Edge(int x) { node = x; }
}
static ArrayList<Edge>[] adjList;
sta... | /content/code_sandbox/graphs/special/EulerTour.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 419 |
```java
package graphs.shortest_path;
/*
* All-Pairs Shortest Path
*/
public class APSP {
static int[][] adjMatrix;
static int[][] p;
static int V;
static void floyd()
{
//adjMatrix contains: directed edges, zero for i=j, INF (1B) otherwise
p = new int[V][V]; //to find the parent on the shortest path... | /content/code_sandbox/graphs/shortest_path/APSP.java | java | 2016-05-29T16:04:20 | 2024-08-15T19:22:08 | Competitive-programming-library | AhmadElsagheer/Competitive-programming-library | 2,432 | 318 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.