[DGD]add:object(), del_object()

Mikael Lind z94lind at mtek.chalmers.se
Fri Dec 1 11:42:09 CET 2000


Assumptions:

  - "file_name" is the 2.4.5 function, which is the same as
    "object_name" except that the leading slash is skipped.

  - "creator_file" returns the creator name of an object; for
    instance, "elemel" for </players/elemel/foo#1974>.
    
  - Strictness level is set to 0 or 1, which means that 0 is used
    as nil value.

Quoting Lord Lerkista from 15:01, November 30, 2000:

> Is any simpler form to do that??
>
> dgd/sys/global.c
>
> [Indented for improved clarity. All comments by Elemel. Each
> comment refers to the line or lines immediately below it.]
>
> void add_object(){
>     if(PRIVILEGED()){
>         /*
>          * Initialize mappings if necessary.
>          */
>         if(objects==0){
>             objects=([]);
>         }
>         if(objetos==0){
>             objetos=([]);
>         }
>
>         /*
>          * Incrementing the value of non-existant mapping index
>          * will automagically create an index-value pair.
>          */
>         objects[creator_file(previous_object())]++;
>         objetos[previous_object()]++;
>     }
> }
>
> void del_object(){
>     object *obj;
>     int i,sz;
>
>     if(PRIVILEGED()){
>         /*
>          * Decrementing the value of a mapping index to 0 will
>          * automagically delete the index-value pair.
>          */
>         objects[creator_file(previous_object())]--;
>
>         obj=map_indices(objetos);
>         objetos=([]);
>         for(i=0,sz=sizeof(obj);i<sz;i++){
>             /*
>              * Since "file_name" returns a name that is unique for
>              * each object, the test is actually equivalent to
>              * (obj[i] != previous_object()).
>              */
>             if(file_name(obj[i])!=file_name(previous_object())){
>                 objetos[obj[i]]++;
>             }
>         }
>     }
> }
>
>
> because i imagine that when the mud has a lot of objects this will
> be too much load!!
>
> this do a list of all the objects in the mud!!

Currently, you are rebuilding the "objetos" mapping at each call to
"del_object". This will, as you correctly assumed, become expensive
when there are many objects in the mud. The following implementation
of "del_object" is a lot more efficient and I believe that it would
work just as well. 

void del_object() {
    if (PRIVILEGED()) {
        /*
         * Decrementing the value of a mapping index to 0 will
         * automagically delete the index-value pair.
         */
        objects[creator_file(previous_object())]--;
	objetos[previous_object()]--;
    }
}

Hope this helps,
Mikael (Elemel)

--
What is my problem with man, you ask? No ... I ask you, what was
man's problem with me // U Don't Know Me / Armand Van Helden
[Sampled, original source unknown]


List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list