src/tiny.js
/**
	 * Create a new shortened url from a given long one. 
	 * In order:
	 * 1)  Check the cache for the url
	 * 2)  Check the table for the url
	 * 3)  Make a new one
	 * @param {string} url the url to encode
	 * @return {string} the shortened url
	 */
Create a new shortened url from a given long one.
In order:
1)  Check the cache for the url
2)  Check the table for the url
3)  Make a new one
@param {string} url the url to encode
@return {string} the shortened url
Create a new shortened url from a given long one . In order : 1 ) Check the cache for the url 2 ) Check the table for the url 3 ) Make a new one @param { string } url the url to encode @return { string } the shortened url
create(url) {
		if (url === this.lastUrl) {
			return this.lastShort;
		}
		const rec = this.reverse[url];
		if (rec) {
			rec.timeout = getTime() + TIMEOUT;
			const encoded = rec.url;
			this.lastUrl = url;
			this.lastShort = encoded;
			return encoded;
		}
		const index = this.findAvailableSlot();
		if (index !== null) {
			const encoded = this.encode(index);
			const rec = {
				timeout: getTime() + TIMEOUT,
				url: url,
				encoded: encoded
			};
			this.table[index] = rec;
			this.forward[encoded] = rec;
			this.reverse[url] = rec;
			this.lastUrl = url;
			this.lastShort = encoded;
			return encoded;
		} else {
			return null;
		}
	}
create ( url ) { if ( url === this . lastUrl ) { return this . lastShort ; } const rec = this . reverse [ url ] ; if ( rec ) { rec . timeout = getTime ( ) + TIMEOUT ; const encoded = rec . url ; this . lastUrl = url ; this . lastShort = encoded ; return encoded ; } const index = this . findAvailableSlot ( ) ; if ( index !== null ) { const encoded = this . encode ( index ) ; const rec = { timeout : getTime ( ) + TIMEOUT , url : url , encoded : encoded } ; this . table [ index ] = rec ; this . forward [ encoded ] = rec ; this . reverse [ url ] = rec ; this . lastUrl = url ; this . lastShort = encoded ; return encoded ; } else { return null ; } }
Create a new shortened url from a given long one.
Create a new shortened url from a given long one .
// check cache first
 /**
		 * First see if the url is already shortened.  If
		 * so, simply update it and return the existing short code.
		 */ /**
		 * Otherwise find the lowest key in the table, and make
		 * a new record.
		 */ // update cache
