toolkit/components/url-classifier/ChunkSet.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/components/url-classifier/ChunkSet.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +//* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef ChunkSet_h__
    1.10 +#define ChunkSet_h__
    1.11 +
    1.12 +
    1.13 +#include "Entries.h"
    1.14 +#include "nsString.h"
    1.15 +#include "nsTArray.h"
    1.16 +
    1.17 +namespace mozilla {
    1.18 +namespace safebrowsing {
    1.19 +
    1.20 +/**
    1.21 + * Store the chunk numbers as an array of uint32_t. We need chunk numbers in
    1.22 + * order to ask for incremental updates from the server.
    1.23 + * XXX: We should optimize this further to compress the many consecutive
    1.24 + * numbers.
    1.25 + */
    1.26 +class ChunkSet {
    1.27 +public:
    1.28 +  ChunkSet() {}
    1.29 +  ~ChunkSet() {}
    1.30 +
    1.31 +  nsresult Serialize(nsACString& aStr);
    1.32 +  nsresult Set(uint32_t aChunk);
    1.33 +  nsresult Unset(uint32_t aChunk);
    1.34 +  void Clear();
    1.35 +  nsresult Merge(const ChunkSet& aOther);
    1.36 +  nsresult Remove(const ChunkSet& aOther);
    1.37 +
    1.38 +  bool Has(uint32_t chunk) const;
    1.39 +
    1.40 +  uint32_t Length() const { return mChunks.Length(); }
    1.41 +
    1.42 +  nsresult Write(nsIOutputStream* aOut) {
    1.43 +    return WriteTArray(aOut, mChunks);
    1.44 +  }
    1.45 +
    1.46 +  nsresult Read(nsIInputStream* aIn, uint32_t aNumElements) {
    1.47 +    return ReadTArray(aIn, &mChunks, aNumElements);
    1.48 +  }
    1.49 +
    1.50 +  uint32_t *Begin() { return mChunks.Elements(); }
    1.51 +  uint32_t *End() { return mChunks.Elements() + mChunks.Length(); }
    1.52 +
    1.53 +private:
    1.54 +  nsTArray<uint32_t> mChunks;
    1.55 +};
    1.56 +
    1.57 +}
    1.58 +}
    1.59 +
    1.60 +#endif

mercurial