time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

node.js (1940B)


      1 /**
      2 * @license Apache-2.0
      3 *
      4 * Copyright (c) 2018 The Stdlib Authors.
      5 *
      6 * Licensed under the Apache License, Version 2.0 (the "License");
      7 * you may not use this file except in compliance with the License.
      8 * You may obtain a copy of the License at
      9 *
     10 *    http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing, software
     13 * distributed under the License is distributed on an "AS IS" BASIS,
     14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     15 * See the License for the specific language governing permissions and
     16 * limitations under the License.
     17 */
     18 
     19 'use strict';
     20 
     21 // MODULES //
     22 
     23 var defineProperty = require( './../../define-property' );
     24 
     25 
     26 // MAIN //
     27 
     28 /**
     29 * List node constructor.
     30 *
     31 * @private
     32 * @constructor
     33 * @param {*} value - node value
     34 * @returns {Node} Node instance
     35 *
     36 * @example
     37 * var node = new Node( 'foo' );
     38 * // returns <Node>
     39 */
     40 function Node( value ) { // eslint-disable-line stdlib/no-redeclare
     41 	// Why a getter? Because some of the list APIs will return the list "node", not the value. In which case, the node API is no longer private and we have to guard against users mucking about (deleting, updating, etc) with property values (in particular, the `next` property).
     42 	defineProperty( this, 'next', {
     43 		'configurable': false,
     44 		'enumerable': true,
     45 		'get': function get() { // eslint-disable-line no-restricted-syntax
     46 			return this._next;
     47 		}
     48 	});
     49 	this.value = value;
     50 
     51 	defineProperty( this, '_next', {
     52 		'configurable': false,
     53 		'enumerable': false,
     54 		'writable': true,
     55 		'value': null
     56 	});
     57 
     58 	// NOTE: strictly speaking, we should not be keeping back-references in a singly-linked list; however, doing so allows us to more efficiently add, remove, and insert list values.
     59 	defineProperty( this, '_prev', {
     60 		'configurable': false,
     61 		'enumerable': false,
     62 		'writable': true,
     63 		'value': null
     64 	});
     65 
     66 	return this;
     67 }
     68 
     69 
     70 // EXPORTS //
     71 
     72 module.exports = Node;