Lawrence  Lesch

Lawrence Lesch

1648302120

TSTL: TypeScript-STL (Standard Template Library, Migrated From C++)

TypeScript Standard Template Library

npm install --save tstl   

Implementation of STL (Standard Template Library) in TypeScript.

  • Containers
  • Iterators
  • Algorithms
  • Functors

TSTL is an open-source project providing features of STL, migrated from C++ to TypeScript. You can enjoy the STL's own specific containers, algorithms and functors in the JavaScript. If TypeScript, you also can take advantage of type restrictions and generic programming with the TypeScript.

Below components are list of provided objects in the TSTL. If you want to know more about the TSTL, then please read the Guide Documents.

Features

Containers

Algorithms

Functors

Installation

NPM Module

Installing TSTL in NodeJS is very easy. Just install with the npm

# Install TSTL from the NPM module
npm install --save tstl

Usage

import std from "tstl";

function main(): void
{
    const map: std.TreeMap<number, string> = new std.TreeMap();

    map.emplace(1, "First");
    map.emplace(4, "Fourth");
    map.emplace(5, "Fifth");
    map.set(9, "Nineth");

    for (let it = map.begin(); !it.equals(map.end()); it = it.next())
        console.log(it.first, it.second);

    const it: std.TreeMap.Iterator<number, string> = map.lower_bound(3);
    console.log(`lower bound of 3 is: ${x.first}, ${x.second}`);
}
main();

Appendix

Author: Samchon
Source Code: https://github.com/samchon/tstl 
License: MIT License

#javascript #typescript #functionalprogramming 

What is GEEK

Buddha Community

TSTL: TypeScript-STL (Standard Template Library, Migrated From C++)
Ari  Bogisich

Ari Bogisich

1593006480

Standard Template Library (STL) in C++ | Lists

The **Standard Template Library (STL) **is a very useful set of template classes containing various containers. One among these containers is Lists. Today we’ll be having a look at Lists in STL. But before we proceed further I’d like to say that if this is your first time learning STL then I’d recommend you have a look at this article before beginning with this one.

With that being said let’s dive further into the topic by knowing what are lists in STL ?

A. Lists in STL

Lists are a type of sequence containers which provides us with constant insertion and deletion time anywhere within the sequence given that we have obtained the corresponding iterator to the same. It also allows us traversal in both the directions.

List containers are implemented as doubly-linked lists. The memory management is done internally by maintaining a link to the previous as well as the next element in the sequence with respect to each element. A significant drawback of lists being that we don’t have direct access to the elements since it uses non contiguous memory allocation for each element in the sequence. Thus in order to get to a specific element in the sequence one has to iterate through the list which takes linear time. Apart from that it also takes up a bit more extra space when compared to vectors, which it uses to keep track of the links to previous and next elements corresponding to each element in the sequence.

#standard-template-library #lists-in-cplusplus #stl #cplusplus #programming-c

Ari  Bogisich

Ari Bogisich

1593029340

Standard Template Library (STL) in C++ | Vectors

The Standard Template Library (STL) in C++ is nothing but a set of template classes which provides us with the widely used data structures such as lists, stacks, maps, etc. along with iterators, functions and algorithms in order to play around with the data elements.

A. Main Components of STL

1.Containers

Containers are nothing but holder objects which stores other objects i.e. it’s elements. A container does the memory management for its elements and provides us with member functions or iterators in order to interact with it’s data elements.

2.Algorithms

Algorithms, defined under the header , are nothing but a collection of several functions which are designed in order to used on any sequence of elements that can be accessed using iterators or pointers. One thing to note about algorithms is that they do not change the way a data structure is organised in any way. They merely deal with the elements within the structure.

3.Iterators

Iterators are something which is used to point at the memory addresses of STL containers’ elements. Thus providing a means to access the data stored within the container. They can be simply thought of as pointers. More about them can be read here.

Now with that being said we are good to go ahead and have a look at our very first container Vector.


B. Vectors in STL

We all know about the commonly used data structure, arrays. A vector can be simply thought of as an array with the added functionality that it’s size can vary over time. Thus we can say that vectors are sequence containers representing arrays that can change it’s size dynamically.

Just like an array, a vector too uses contiguous memory allocation for its elements thus we can make use of offsets in order to access the elements of a vector. Internally vectors make use of dynamically allocated arrays. This array may need to be reallocated in order to grow in size thus resulting in a costly operation of reallocation and copying the elements. Thus vectors do not reallocate each time instead they have an extra amount of space which is greater than their actual size (current size of the vector) and re-allocations usually happen at logarithmic intervals. Thus, vectors occupy more space when compared to an array in exchange of dynamic nature and efficient memory management.

C. Let’s have a look at the syntax

We need to import the header  so that we can make use of vectors

#include <vector>

Now, in order to declare a vector we use the following syntax

vector vector_name;

Eg : vector v;

This declares a vector with 0 elements in it.

D. Different ways of vector declaration and initialisation

#include <iostream>
#include <vector>

using namespace std;
int main()
{
 vector <int> myVec;     // simple declaration
 myVec.assign(10, 33);   // 10 ints with a value of 33

 vector <int> v{1,2,3};  // initialise on the go
 vector <int> v1(3);     // 3 ints with value of 0
 vector <int> v2(3,7);   // 3 ints with value of 7
 return 0;
}

#vector #standard-template-library #cplusplus #stl #programming-c

Shaylee  Lemke

Shaylee Lemke

1590240840

The numerical algorithms that are found in the Standard Template Library (STL)

In this article I will discuss the numerical algorithms that are found in the Standard Template Library (STL). These algorithms do not replace the math library for the types of functions found in cmath but provide a different set of algorithms for solving certain numerical processing problems.

#c #c# #c++ #programming-c

Adaline  Kulas

Adaline Kulas

1594166040

What are the benefits of cloud migration? Reasons you should migrate

The moving of applications, databases and other business elements from the local server to the cloud server called cloud migration. This article will deal with migration techniques, requirement and the benefits of cloud migration.

In simple terms, moving from local to the public cloud server is called cloud migration. Gartner says 17.5% revenue growth as promised in cloud migration and also has a forecast for 2022 as shown in the following image.

#cloud computing services #cloud migration #all #cloud #cloud migration strategy #enterprise cloud migration strategy #business benefits of cloud migration #key benefits of cloud migration #benefits of cloud migration #types of cloud migration

Lawrence  Lesch

Lawrence Lesch

1648302120

TSTL: TypeScript-STL (Standard Template Library, Migrated From C++)

TypeScript Standard Template Library

npm install --save tstl   

Implementation of STL (Standard Template Library) in TypeScript.

  • Containers
  • Iterators
  • Algorithms
  • Functors

TSTL is an open-source project providing features of STL, migrated from C++ to TypeScript. You can enjoy the STL's own specific containers, algorithms and functors in the JavaScript. If TypeScript, you also can take advantage of type restrictions and generic programming with the TypeScript.

Below components are list of provided objects in the TSTL. If you want to know more about the TSTL, then please read the Guide Documents.

Features

Containers

Algorithms

Functors

Installation

NPM Module

Installing TSTL in NodeJS is very easy. Just install with the npm

# Install TSTL from the NPM module
npm install --save tstl

Usage

import std from "tstl";

function main(): void
{
    const map: std.TreeMap<number, string> = new std.TreeMap();

    map.emplace(1, "First");
    map.emplace(4, "Fourth");
    map.emplace(5, "Fifth");
    map.set(9, "Nineth");

    for (let it = map.begin(); !it.equals(map.end()); it = it.next())
        console.log(it.first, it.second);

    const it: std.TreeMap.Iterator<number, string> = map.lower_bound(3);
    console.log(`lower bound of 3 is: ${x.first}, ${x.second}`);
}
main();

Appendix

Author: Samchon
Source Code: https://github.com/samchon/tstl 
License: MIT License

#javascript #typescript #functionalprogramming