HttpRequest.GetHashCode () - how often do collisions occur?

I am trying to find a reliable way to uniquely identify and track various HttpRequests on an ASP.NET website.

Does anyone know anything about implementing HttpRequest.GetHashCode ()? In particular, how often do clashes occur?

I understand that HashCodes is not guaranteed to be unique. What I'm trying to understand is statistically how often I could expect HashCode to repeat.

The system I mean will gracefully handle HashCode conflicts, but I want to make sure they are at least as unique as 1 in 1000 or so.

+3
source share
1 answer

, - .

, - , .

, - :

class TrackableHttpRequest : IEquatable<TrackableHttpRequest>
{
    readonly Guid id = Guid.NewGuid();

    public Guid Id { get { return this.id; } }
    public HttpRequest Request { get; set; }

    public override Int32 GetHashCode()
    {
        return this.Id.GetHashCode();
    }

    public override Boolean Equals(Object obj)
    {
        return this.Equals(obj as TrackableHttpRequest);
    }

    public bool Equals(TrackableHttpRequest other)
    {
        if (other == null)
            return false;

        return this.Id == other.Id;
    }
}
+5

Source: https://habr.com/ru/post/1718380/


All Articles