toolkit/components/url-classifier/ChunkSet.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 //* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef ChunkSet_h__
     7 #define ChunkSet_h__
    10 #include "Entries.h"
    11 #include "nsString.h"
    12 #include "nsTArray.h"
    14 namespace mozilla {
    15 namespace safebrowsing {
    17 /**
    18  * Store the chunk numbers as an array of uint32_t. We need chunk numbers in
    19  * order to ask for incremental updates from the server.
    20  * XXX: We should optimize this further to compress the many consecutive
    21  * numbers.
    22  */
    23 class ChunkSet {
    24 public:
    25   ChunkSet() {}
    26   ~ChunkSet() {}
    28   nsresult Serialize(nsACString& aStr);
    29   nsresult Set(uint32_t aChunk);
    30   nsresult Unset(uint32_t aChunk);
    31   void Clear();
    32   nsresult Merge(const ChunkSet& aOther);
    33   nsresult Remove(const ChunkSet& aOther);
    35   bool Has(uint32_t chunk) const;
    37   uint32_t Length() const { return mChunks.Length(); }
    39   nsresult Write(nsIOutputStream* aOut) {
    40     return WriteTArray(aOut, mChunks);
    41   }
    43   nsresult Read(nsIInputStream* aIn, uint32_t aNumElements) {
    44     return ReadTArray(aIn, &mChunks, aNumElements);
    45   }
    47   uint32_t *Begin() { return mChunks.Elements(); }
    48   uint32_t *End() { return mChunks.Elements() + mChunks.Length(); }
    50 private:
    51   nsTArray<uint32_t> mChunks;
    52 };
    54 }
    55 }
    57 #endif

mercurial