Hash tables manager beta

By FLCL on Oct 26, 2007

Add items, delete items, edit items, free hash tables, and make new hash tables with this snippet.

/* 

    This snippet allows you to manipulate hash tables very, very easily. Add items, delete items, edit items, add hash tables, and free hash tables with this snippet. 

    ; Syntax:
        Just type in the following syntax to add an item: <item> <item data> - whenever you type in the editbox (besides evaluated commands) it will add the first string and second string to the selected hash table.
        .remove (N) - removes the Nth item in the hash table.
        .edit (N) (new data) - edits the Nth item in the hash table with the new string.
        .make (hash table) (hash table size) - creates a new hash table with the specifications you made.
        .free (hash table) - removes a hash table from the list.
    ****** Please note that for every command (except for .make) you must have a hash table selected in the list box. ******

*/

alias filterhsh { 
  if ($window($w3)) { clear $w3 }
  window -l15ke $w3
  var %x = 1
  while ($hget(%x)) { 
    aline -l $w3 $+(%x,.,$v1)
    inc %x
  }
}
alias -l w3 return @filterhash
menu @filterhash { 
  dclick:{ 
    if ($gettok($sline($w3,1),1,46) isnum) { 
      set -e %hsh $gettok($sline($w3,1),2,46) 
      clear @filterhash
      hsave -o $gettok($sline($w3,1),2,46) $+($gettok($sline($w3,1),2,46),.,hsh) 
      var %x = 1
      while ($hget(%hsh,%x).item) { 
        aline -p $w3 $v1 - $hget(%hsh,%x).data 
        inc %x
      }
    }
  }
}

on *:input:@filterhash:{ 
  if ($1 && $2- && !$ctrlenter && /* !iswm $1-) { 
    if ($1 = .remove && $2) {
      if ($gettok($sline($w3,1),1,46) isnum) {  
        hdel %hsh $hget(%hsh,$2).item
        dline $w3 $2
      } 
    }
    if ($1 = .edit && $2 isnum && $3-) {
      if ($gettok($sline($w3,1),1,46) isnum) { 
        set %hsh2 $hget(%hsh,$2).item
        hdel %hsh $hget(%hsh,$2).item
        dline $w3 $2 
        hadd -m %hsh %hsh2 $3-
        aline -p $w3 %hsh2 - $3-
        unset %hsh2
      }
    }  
    if ($1 = .make && $2 && $3 isnum) { 
      if (!$hget($2)) { hmake $2 $3 }
      aline -l $w3 $calc($hget(0) + 1)
    }
    elseif ($1 = .free && $2) { 
      if ($gettok($sline($w3,1),1,46) isnum) { 
        set -e %hsh $gettok($sline($w3,1),2,46)
        clear @filterhash
        dline -l $w3 $sline($w3,1).ln
        hfree %hsh
        unset %hsh
      }
    }
    elseif ($gettok($sline($w3,1),1,46) isnum) { 
      hadd -m %hsh $1 $2-
      aline -p $w3 $1 - $2-
    }
  }
}

on *:close:@filterhash: unset %hsh 

/*

        Hash tables manager - FLCL
            Any editing/redistribution of this script is forbidden.

*/

Comments

Sign in to comment.
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.