Ejemplo n.º 1
0
        static void _hash_enter(HashHeader ht, int key, Object data)
        {
            /* precondition: there is no entry for <Key> yet */
            //HashLink temp;
            //int i;

            /*
             * temp = new HashLink();
             * temp.Key = key;
             * temp.Next = ht.Buckets[HashKey(ht, key)];
             * temp.Data = data;
             * ht.Buckets[HashKey(ht, key)] = temp;
             * if( ht.Klistlen >= ht.Klistsize )
             * {
             *  //ht.Keylist = (int)realloc( ht.Keylist, sizeof( ht.Keylist ) * ( ht.Klistsize *= 2 ) );
             * }
             * for( i = ht.Klistlen; i >= 0; i-- )
             * {
             *  if (ht.Keylist[i - 1] < key)
             *  {
             *      ht.Keylist[i] = key;
             *      break;
             *  }
             *  ht.Keylist[ i ] = ht.Keylist[ i - 1 ];
             * }
             * ht.Klistlen++;
             */
            return;
        }
Ejemplo n.º 2
0
 static void InitHashTable(HashHeader ht, int recSize, int tableSize)
 {
     ht.RecSize   = recSize;
     ht.TableSize = tableSize;
     ht.Buckets   = new LinkedList <HashLink>();
     ht.Keylist   = new LinkedList <int>();
     ht.Klistlen  = 0;
 }
Ejemplo n.º 3
0
        int HashEnter(HashHeader ht, int key, Object data)
        {
            Object temp = hash_find(ht, key);

            if (temp)
            {
                return(0);
            }

            _hash_enter(ht, key, data);
            return(1);
        }
Ejemplo n.º 4
0
        static Object hash_find(HashHeader ht, int key)
        {
            HashLink scan = null;

            //scan = ht.Buckets[HashKey(ht, key)];

            while (scan != null && scan.Key != key)
            {
                scan = scan.Next;
            }

            return(scan != null ? scan.Data : null);

            return(null);
        }
Ejemplo n.º 5
0
        Object HashFindOrCreate(HashHeader ht, int key)
        {
            Object rval;

            rval = hash_find(ht, key);
            if (rval)
            {
                return(rval);
            }

            //rval = new char[ ht.RecSize ];
            _hash_enter(ht, key, rval);

            return(rval);
        }
Ejemplo n.º 6
0
        Object HashRemove(HashHeader ht, int key)
        {
            HashLink scan = null;

            // scan = ht.Buckets + HashKey(ht, key);

            while (scan != null && (scan).Key != key)
            {
                scan = (scan).Next;
            }

            if (scan != null)
            {
                //HashLink temp = null;
                HashLink aux;
                int      i = 0;

                //temp = (HashLink)( scan ).Data;
                aux  = scan;
                scan = aux.Next;
                aux  = null;

                //for( i = 0; i < ht.Klistlen; i++ )
                //    if (ht.Keylist[i] == key)
                //        break;

                if (i < ht.Klistlen)
                {
                    //memmove( ht.Keylist + i, ht.Keylist + i + 1, ( ht.Klistlen - i )
                    //         * sizeof( ht.Keylist ) );
                    ht.Klistlen--;
                }

                //return temp;
            }

            return(null);
        }
Ejemplo n.º 7
0
 static void DestroyHashTable( HashHeader ht, Object gman )
 {
     ht.Buckets.Clear();
     ht.Keylist.Clear();
     return;
 }
Ejemplo n.º 8
0
 static void DestroyHashTable(HashHeader ht, Object gman)
 {
     ht.Buckets.Clear();
     ht.Keylist.Clear();
     return;
 }
Ejemplo n.º 9
0
 static void InitHashTable( HashHeader ht, int recSize, int tableSize )
 {
     ht.RecSize = recSize;
     ht.TableSize = tableSize;
     ht.Buckets = new LinkedList<HashLink>();
     ht.Keylist = new LinkedList<int>();
     ht.Klistlen = 0;
 }
Ejemplo n.º 10
0
 int HashKey(HashHeader ht, int key)
 {
     return((((int)(key)) * 17) % (ht).TableSize);
 }
Ejemplo n.º 11
0
        public static Exit.Direction FindPath(int inRoomIndexNumber, int outRoomIndexNumber, CharData ch, int depth, bool inZone)
        {
            RoomTemplate herep;
            RoomTemplate startp;
            Exit         exitp;
            RoomQ        tmp_q;
            RoomQ        q_head;
            RoomQ        q_tail;
            HashHeader   x_room = null;
            bool         throughDoors;
            int          i;
            int          tmp_room;
            int          count = 0;

            // TODO: Re-enable this.
            return(Exit.Direction.invalid);

            if (depth < 0)
            {
                throughDoors = true;
                depth        = -depth;
            }
            else
            {
                throughDoors = false;
            }

            startp = Room.GetRoom(inRoomIndexNumber);

            InitHashTable(x_room, sizeof(int), 2048);
            //HashEnter(x_room, inRoomIndexNumber, null);

            /* initialize queue */
            q_head        = new RoomQ();
            q_tail        = q_head;
            q_tail.RoomNR = inRoomIndexNumber;
            q_tail.NextQ  = null;

            while (q_head != null)
            {
                herep = Room.GetRoom(q_head.RoomNR);
                /* for each room test all directions */
                if (herep.Area == startp.Area || inZone == false)
                {
                    /*
                     * only look in this zone...
                     * saves cpu time and makes world safer for players
                     */
                    for (i = 0; i < Limits.MAX_DIRECTION; i++)
                    {
                        exitp = herep.ExitData[i];
                        if (ExitOk(exitp) != 0 && (throughDoors ? GO_OK_SMARTER :
                                                   Macros.IsSet((int)Room.GetRoom(q_head.RoomNR).ExitData[i].ExitFlags, (int)Exit.ExitFlag.closed)))
                        {
                            /* next room */
                            tmp_room = herep.ExitData[i].TargetRoom.IndexNumber;
                            if (tmp_room != outRoomIndexNumber)
                            {
                                /*
                                 * shall we add room to queue ?
                                 * count determines total breadth and depth
                                 */
                                if (!hash_find(x_room, tmp_room) &&
                                    (count < depth))
                                /* && !IS_SET( RM_FLAGS(tmp_room), DEATH ) ) */
                                {
                                    ++count;
                                    /* mark room as visted and put on queue */

                                    tmp_q        = new RoomQ();
                                    tmp_q.RoomNR = tmp_room;
                                    tmp_q.NextQ  = null;
                                    q_tail.NextQ = tmp_q;
                                    q_tail       = tmp_q;

                                    /* Ancestor for first layer is the direction */

                                    /*HashEnter(x_room, tmp_room,
                                     *          ((long)hash_find(x_room, q_head.RoomNR) == -1)
                                     *          ? (Object)(i + 1)
                                     *          : hash_find(x_room, q_head.RoomNR));*/
                                }
                            }
                            else
                            {
                                /* have reached our goal so free queue */
                                tmp_room = q_head.RoomNR;
                                for (; q_head != null; q_head = tmp_q)
                                {
                                    tmp_q  = q_head.NextQ;
                                    q_head = null;
                                }
                                /* return direction if first layer */

                                /*if ((long)hash_find(x_room, tmp_room) == -1)
                                 * {
                                 *  if (x_room.Buckets)
                                 *  {
                                 *      // junk left over from a previous track
                                 *      DestroyHashTable(x_room, null);
                                 *  }
                                 *  return (i);*/
                                //}
                                //else
                                {
                                    /* else return the Ancestor */
                                    //long j;

                                    /*j = (long)hash_find(x_room, tmp_room);
                                     * if (x_room.Buckets)
                                     * {
                                     *  // junk left over from a previous track
                                     *  DestroyHashTable(x_room, null);
                                     * }
                                     * return (-1 + j);*/
                                }
                            }
                        }
                    }
                }

                /* free queue head and point to next entry */
                tmp_q  = q_head.NextQ;
                q_head = null;
                q_head = tmp_q;
            }

            /* couldn't find path */

            /*if (x_room.Buckets)
             * {
             *  // junk left over from a previous track
             *  DestroyHashTable(x_room, null);
             * }*/
            return(Exit.Direction.invalid);
        }
Ejemplo n.º 12
0
        static void _hash_enter( HashHeader ht, int key, Object data )
        {
            /* precondition: there is no entry for <Key> yet */
            //HashLink temp;
            //int i;

            /*
            temp = new HashLink();
            temp.Key = key;
            temp.Next = ht.Buckets[HashKey(ht, key)];
            temp.Data = data;
            ht.Buckets[HashKey(ht, key)] = temp;
            if( ht.Klistlen >= ht.Klistsize )
            {
                //ht.Keylist = (int)realloc( ht.Keylist, sizeof( ht.Keylist ) * ( ht.Klistsize *= 2 ) );
            }
            for( i = ht.Klistlen; i >= 0; i-- )
            {
                if (ht.Keylist[i - 1] < key)
                {
                    ht.Keylist[i] = key;
                    break;
                }
                ht.Keylist[ i ] = ht.Keylist[ i - 1 ];
            }
            ht.Klistlen++;
            */
            return;
        }
Ejemplo n.º 13
0
        static Object hash_find( HashHeader ht, int key )
        {
            HashLink scan = null;
            //scan = ht.Buckets[HashKey(ht, key)];

            while (scan != null && scan.Key != key)
                scan = scan.Next;

            return scan != null ? scan.Data : null;
            return null;
        }
Ejemplo n.º 14
0
        Object HashRemove( HashHeader ht, int key )
        {
            HashLink scan = null;

            // scan = ht.Buckets + HashKey(ht, key);

            while (scan != null && (scan).Key != key)
                scan = ( scan ).Next;

            if( scan != null )
            {
                //HashLink temp = null;
                HashLink aux;
                int i = 0;

                //temp = (HashLink)( scan ).Data;
                aux = scan;
                scan = aux.Next;
                aux = null;

                //for( i = 0; i < ht.Klistlen; i++ )
                //    if (ht.Keylist[i] == key)
                //        break;

                if( i < ht.Klistlen )
                {
                    //memmove( ht.Keylist + i, ht.Keylist + i + 1, ( ht.Klistlen - i )
                    //         * sizeof( ht.Keylist ) );
                    ht.Klistlen--;
                }

                //return temp;
            }

            return null;
        }
Ejemplo n.º 15
0
 int HashKey( HashHeader ht, int key )
 {
     return ( ( ( (int)( key ) ) * 17 ) % ( ht ).TableSize );
 }
Ejemplo n.º 16
0
        Object HashFindOrCreate( HashHeader ht, int key )
        {
            Object rval;

            rval = hash_find(ht, key);
            if( rval )
                return rval;

            //rval = new char[ ht.RecSize ];
            _hash_enter(ht, key, rval);

            return rval;
        }
Ejemplo n.º 17
0
        int HashEnter( HashHeader ht, int key, Object data )
        {
            Object temp = hash_find( ht, key );
            if( temp )
                return 0;

            _hash_enter( ht, key, data );
            return 1;
        }