Vector in Hack

In Hack Language Vectors are an integer-indexed (zero-based) collection.
Vectors allows random access to its elements with minimum complexity.
All operation like insertions, deletion and retrievals can be performed in vector with minimal time complexity.
A simple example demonstrating the use of vector in Hack language is shown below.
Example:
<?hh
function  main_func() {
  $vec = Vector {50, 150};
  $vec->add(250);
  $vec->add(300);
  $vec->add(350);
  $vec[] = 400;
  $vec->removeKey(1);
  foreach ($vec as $val) {
    echo $val . "\n";
  }
}
main_func();
Output:
50
250
300
350
400
As we can see in the above example that how we can simply create a vector , insertion of values, removal of elements as well as how we can operate through the elements.
Hope the above tutorial helped you. For any queries and information please do mention it in the comments below.

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.