Hash table aliases

By Saeed on Sep 28, 2007

/hedit or $hedit


A simple alias that edits the data of a specified item in a hash table through hadd and hdel. You must specify all the required parameters otherwise the snippet will not work. See the comments below for more information.


/hmove


Simple alias that copies a hash table into a new one through a really simple method. It stores all the item from the first hash table into a temporary txt file. Then it reads the text file and converts the data from the txt file into the new hash table.


/hpaste


Simple alias that does the same as /hmove but keeps the first table.

;--------------------------------
;--- /hedit - Saeed * 2007 ------
;--------------------------------
;--- Usage ----------------------
;--- /hedit hashname item data --
;--- $hedit(hashname,item,data) -
;--------------------------------
;--------------------------------

alias hedit { 
  if ($isid) { 
    if ($hget($1)) { 
      if ($2) { 
        if ($hget($1,$2).item) && ($hget($1,$2).data) {
          if ($3-) { 
            hdel $1 $2 
            hadd $1 $2 $3-
          }
        }
      }
    }
  }
  else { 
    if ($hget($1)) { 
      if ($2) { 
        if ($hget($1,$2).item) && ($hget($1,$2).data) {  
          if ($3-) { 
            hdel $1 $2
            hadd $1 $2 $3-
          }
        } 
      }
    }
  } 
} 

;-------------------------------------------
;--- /hmove - Saeed * 2007 -----------------
;-------------------------------------------
;------ Usage ------------------------------
;--- /hmove firsthashname -> newhashname ---
;-------------------------------------------

alias hmove { 
  if ($1 && $2 && $3) { 
    if ($hget($1) && !$hget($2)) { 
      var %x 1 
      write tmpmoveforhash.txt
      while ($hget($1,%x).item) {  
        write tmpmoveforhash.txt $v1 $hget($1,%x).data
        inc %x
      }
      hmake $2 $3
      var %x 1
      while ($read(tmpmoveforhash.txt,%x)) { 
        hadd -m $2 $v1
        inc %x
      }
      hfree $1 
      remove tmpmoveforhash.txt
    }
  }    
}

Comments

Sign in to comment.
RubixCube   -  Sep 29, 2007

Lol, it\'s too bad I have to wait seven days until I can rate. Then I could actually submit my scores without having to give the user an idea of my rating.

 Respond  
Akishoot   -  Sep 29, 2007

*can - Silly keyboard

 Respond  
Akishoot   -  Sep 29, 2007

I like users that can\'t rate/give tips like him. ^ XD

 Respond  
RubixCube   -  Sep 29, 2007

Pros:

  • The /hedit is really convenient instead of using hadd and hdel.
  • The /hmove is really useful for me as well in case I want to rename a hash table, I can copy all of the data.

Cons:

  • /hedit can easily be done in a different method such as hload and hsave. I find it irritable to get the remove echo every time.
  • The /hpaste is completely useless. It\'s basically /hmove but keeping the first hash table, you might as well include that in the /hmove alias instead of creating an entire new alias and wasting space.

If you included a hash view and(or) editor that would be fantastic. I\'m sorry but right now, these aren\'t too worthy of a high score. My rating: 5.5/10-5.9/10

  • RubixCube
 Respond  
Saeed   -  Sep 29, 2007

Indeed, but the purpose and actions /hedit takes is much simpler to use then using hdel and hadd. If I don\'t specify this specific format, it won\'t really edit. I could make the format of /hedit a little different somehow if you would like but right now that is quite necessary. Anything I can improve on in this snippet to make it worth more than a 3.0?

 Respond  
RusselB   -  Sep 29, 2007

Your /hedit is identical in format and usage to that of /hadd

 Respond  
Saeed   -  Sep 29, 2007
  • two
 Respond  
Saeed   -  Sep 29, 2007

Interesting idea, I have not really covered those too. I\'ll see what I can do Olliegod.

 Respond  
Olliegod   -  Sep 29, 2007

The hmove alias could be much simpler.
Check the help file for /hsave and /hload

 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.