This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function UnionFind(n) { | |
| this.id = [...Array(n)].map((_, i) => i) | |
| this.sz = [...Array(n)].map(_ => 1) | |
| this.actual = [...this.id] | |
| } | |
| UnionFind.prototype._root = function (id) { | |
| while(id != this.id[id]) | |
| id = this.id[id] | |
| return id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function UnionFind(n) { | |
| this.id = [...Array(n)].map((_, i) => i) | |
| this.sz = [...Array(n)].map(_ => 1) | |
| this.max = [...this.id] | |
| } | |
| UnionFind.prototype._root = function (id) { | |
| let max = id | |
| while(id != this.id[id]) { | |
| id = this.id[id] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function UnionFind(n) { | |
| this.id = [...Array(n)].map((_, i) => i) | |
| this.sz = [...Array(n)].map(_ => 1) | |
| this.max = 0 | |
| } | |
| UnionFind.prototype._root = function (id) { | |
| while (id !== this.id[id]) | |
| id = this.id[id] | |
| return id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mergeSort(array) { | |
| let len = array.length | |
| let b = 1 | |
| while (b < len) { | |
| for (let i = 0; i + b < len; i += b * 2) { | |
| let l = i | |
| let r = i + b | |
| let left = array.slice(l, l+b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function mergeSort(array) { | |
| let n = array.length | |
| if (n === 1) { | |
| return array | |
| } | |
| let left = array.slice(0, Math.floor(n/2)) | |
| let right = array.slice(Math.floor(n/2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function merge(left, right) { | |
| // REMEMBER THAT BOTH LEFT AND RIGHT ARE ALREADY ORDERED | |
| let merged = [] // result array to return | |
| let i = 0 | |
| let j = 0 | |
| while ( i < left.length && j < right.length ) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { ErrorHandler } from '@angular/core' | |
| export class AppErrorHandler implements ErrorHandler { | |
| handleError(error) { | |
| alert( 'An error occured.' ) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Component, OnInit } from '@angular/core'; | |
| import { AuthService } from '../services/auth.service'; | |
| import { Router } from '@angular/router' | |
| import { UnauthError } from '../common/unauth-error' | |
| import { AppError } from '../common/app-error' | |
| @Component({ | |
| selector: 'app-login', | |
| templateUrl: './login.component.html', | |
| styleUrls: ['./login.component.css'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Injectable } from '@angular/core' | |
| import { HttpClient, HttpErrorResponse } from '@angular/common/http' | |
| import { tap, catchError } from 'rxjs/operators' | |
| import { throwError } from 'rxjs' | |
| // import our custom classes | |
| import { AppError } from '../common/app-error'; | |
| import { UnauthError } from '../common/unauth-error'; | |
| @Injectable({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { AppError } from './app-error'; | |
| export class UnauthError extends AppError { } |