Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

# Engine.HashMapNameToObject

00001 00002 00003 00004 00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135

    class HashMapNameToObject extends Core.Object;

    var private array<HashMapBucket> Buckets;

    const NUM_BUCKETS = 256;

    function int HashKey(string inKey)
    {
        return abs(Hash(inKey, NUM_BUCKETS));
    }

    final function Empty()
    {
        local int i;

        for (i=0; i<Buckets.length; ++i)
            Buckets[i].Empty();

        Buckets.Remove(0, Buckets.length);
    }

    final function bool HasKey(string inKey)
    {
        local int bucket;

        bucket = HashKey(inKey);

        if (bucket >= Buckets.length)
            return false;

        return Buckets[bucket].HasKey(inKey);
    }

    final function Add(String inKey, Object object)
    {
        local int bucket;

        bucket = HashKey(inKey);

        if (bucket >= Buckets.length || Buckets[bucket] == None)
            Buckets[bucket] = new class'HashMapBucket';

        Buckets[bucket].Add(inKey, object);
    }

    final function Remove(string inKey)
    {
        local int bucket;

        bucket = HashKey(inKey);

        Buckets[bucket].Remove(inKey);
    }

    //returns the first object with key=inKey, or None
    final function Object Lookup(string inKey)
    {
        local int bucket;

        bucket = HashKey(inKey);

        if (bucket >= Buckets.length || Buckets[bucket] == None)
            return None;

    #if IG_SHARED // Ryan: Don't assume there is a valid bucket
    	if (Buckets[bucket] == None)
    		return None;
    #endif // IG

        return Buckets[bucket].Lookup(inKey);
    }

    final function HashMapBucket GetBucket(string inKey)
    {
        local int bucket;

        bucket = HashKey(inKey);

        if (bucket >= Buckets.length)
            return None;

        return Buckets[HashKey(inKey)];
    }

    //for debugging
    final function int GetBucketIndex(string inKey)
    {
        return HashKey(inKey);
    }

    final function Profile()
    {
        //calculate the bucket size mean and standard deviation
        local float Mean;
        local float Variance;
        local float StandardDeviation;
        local int i;
        local int used;
        local int max;

        //mean
        for (i=0; i<Buckets.length; ++i)
        {
            if (Buckets[i] != None)
            {
                ++used;
                if (Buckets[i].Entries.length > max)
                    max = Buckets[i].Entries.length;
                Mean += Buckets[i].Entries.length;
            }
        }
        Mean = Mean / Buckets.length;

        //add squared deviations
        for (i=0; i<Buckets.length; ++i)
            if (Buckets[i] != None)
                Variance += Square(Buckets[i].Entries.length - Mean);
            else
                Variance += Square(Mean);
        Variance = Variance / Buckets.length;

        //standard deviation
        StandardDeviation = Sqrt(Variance);

        log(name$"::Profile(): NUM_BUCKETS="$NUM_BUCKETS$", BucketsAllocated="$Buckets.length$", BucketsUsed="$used$", MaxBucketSize="$max$", MeanBucketSize="$mean$", StandardDeviation="$StandardDeviation);

        /* TMC uncomment for a full dump of each bucket's stats
        for (i=0; i<Buckets.length; ++i)
            if (Buckets[i] != None)
                log("  -> Bucket #"$i$": Size="$Buckets[i].Entries.length$" ("$abs(Buckets[i].Entries.length - Mean) / StandardDeviation$" s.d.(s) from mean)");
            else
                log("  -> Bucket #"$i$": Size=[unallocated:0] ("$Mean / StandardDeviation$" s.d.(s) from mean)");
        */
    }

Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation
previous class next class | frames no frames

Class file time: ne 5.9.2004 16:01:22.000 - Creation time: st 23.5.2018 00:10:44.035 - Created with UnCodeX