Array

By Ayon on Jun 05, 2009

This is a handy little thing to use if you want to simplify the use of hash tables...

Syntax:
$array(Table|N[,Item|N]) - Retrive array info

/array -new

Quick update:

  • Added save/load function (Uses ini format)
/*
  Array :: by Ayon
  ---------------------

  How to use it:

  $array(Table|N[,Item|N]) - Retrive array info

  /array -new <Table> - Adds a new table
  /array -item[add] <Table> <Item> <Data> - Adds a new item to table
  /array -item[mod] <Table> <Item> <Data> - Modifies the data in an item
  /array -item[del] <Table> <Item> - Deletes an item
*/

alias array {
  if ($isid) { 
    if (!$hget($1)) && ($1 !isnum) { return * No such table. }
    return $iif(!$regex($2,/(.+)/g),$hget($1),$iif($2 isnum,$hget($1,$int($2)).item,$hget($1,$2)))
  }
  else { 
    if ($1 == -new) {
      if (!$2) { echo -s * Missing parameters. Syntax: /array -new <Table> [Size] (Size is 100 by default) | return }
      if ($hget($2)) { echo -s * Table $+(",$2,") allready exists. | return }
      hmake $2 $iif($3,$3,100)
      echo -s * Table $+(",$2,") was succsessfully created.
    }
    elseif ($regex($1,\-\item\[(add|mod|del)\])) {
      if (!$2) || (!$3) { echo -s * Missing paramteres. Syntax: /array $+(-item[add,$chr(124),mod,$chr(124),del]) <Table> <Item> [data] | return }
      if (!$hget($2)) { echo -s * No such table. | return }
      if ($regml(1) == add) {
        if (!$4) { echo -s * Missing data. | return }
        if ($hget($2,$3)) { echo -s * Item $+(",$3,") allready exist in $+(",$2,".) | return }
        hadd $2 $3 $4-
        echo -s * Item $+(",$3,") was added to $+(",$2,".)
      }
      elseif ($regml(1) == mod) {
        if (!$4) { echo -s * Missing data. | return }
        hdel $2 $3 | hadd $2 $3 $4-
        echo -s * Item $+(",$3,") was modified.
      }
      elseif ($regml(1) == del) { hdel $2 $3 | echo -s * Item $+(",$3,") was deleted from $+(",$2,".) }
      else { echo -s * $regml(1) is not a valid item option. | return }
    }
    elseif ($regex($1,/^\-(save|load)$/g)) { 
      if ($regml(1) == load) && (!$hget($2)) { echo -s * Could not load table file. No such table. | return }
      $+(h,$regml(1)) -i $2 $3 $2
    }
  }
}

Comments

Sign in to comment.
NXArmada   -  Feb 08, 2010

Deleted.

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.