Skip to content

Instantly share code, notes, and snippets.

View topnotch48's full-sized avatar

n.yakovenko topnotch48

  • behind your back
View GitHub Profile
@topnotch48
topnotch48 / time.fs
Created November 20, 2018 19:17
a simple profiling function for f#, measures both real and cpu timings.
open System.Diagnostics
let time f =
let proc = Process.GetCurrentProcess()
let cpu_time_stamp = proc.TotalProcessorTime
let timer = new Stopwatch()
timer.Start()
try
f()
finally
public HashSet<T> BFS<T>(Graph<T> graph, T start) {
var visited = new HashSet<T>();
if (!graph.AdjacencyList.ContainsKey(start))
return visited;
var queue = new Queue<T>();
queue.Enqueue(start);
while (queue.Count > 0) {
class MergeSort
{
public static void MergeSort(int[] input, int low, int high)
{
if (low < high)
{
int middle = (low + high) / 2;
MergeSort(input, low, middle);
MergeSort(input, middle + 1, high);
Merge(input, low, middle, high);
private void ReCalculateDown()
{
int index = 0;
while (HasLeftChild(index))
{
var biggerIndex = GetLeftChildIndex(index);
if (HasRightChild(index) && GetRightChild(index) > GetLeftChild(index))
{
biggerIndex = GetRightChildIndex(index);
}
public class MinHeap
{
private readonly int[] _elements;
private int _size;
public MinHeap(int size)
{
_elements = new int[size];
}
public static void quickSort(int[] A, int left, int right)
{
if(left > right || left <0 || right <0) return;
int index = partition(A, left, right);
if (index != -1)
{
quickSort(A, left, index - 1);
quickSort(A, index + 1, right);
function initComponent<TValue, TComponent extends FieldEditorComponent<TValue>>(c: { new (...args: any[]): TComponent },
wellKnownField: WellKnownField,
criteriaValue: any,
valueChangeHandler: (e: FieldEditorValueChangeEvent<TValue>) => void
): TestCtx<TComponent> {
let testCtx = createTestContext(c);
tick();
let field = (<MatterContext>TestBed.get(MatterContext)).matterDefinition!.fieldsDefinition.getWellKnownField(wellKnownField);
let fc = FieldCriteriaFactory.buildCriteria(field, SearchFieldOperator.EQ, criteriaValue);
(<any>testCtx.component).value = fc.value;
module Array =
open System.Collections.Generic
let toMap<'TItem when 'TItem : equality> array =
let map = array |> Seq.fold (fun (map: Dictionary<'TItem, int>) ch ->
if map.ContainsKey(ch) then
map.[ch] <- map.[ch] + 1
else
map.Add(ch, 1)
...
frameworks: [
'parallel',
'jasmine'
],
plugins: [
"karma-jasmine",
"karma-chrome-launcher",
"karma-junit-reporter",
"karma-spec-reporter",
describe('#productions Production wizard bates settings', () => {
configureTestSuite();
beforeAll(done => (async () => {
TestBed.configureTestingModule({
imports: modules,
providers: [defaultGlobalProvidersForTests]
});