toolkit/components/url-classifier/ChunkSet.h

branch
TOR_BUG_9701
changeset 14
925c144e1f1f
equal deleted inserted replaced
-1:000000000000 0:6e765a78ce36
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/. */
5
6 #ifndef ChunkSet_h__
7 #define ChunkSet_h__
8
9
10 #include "Entries.h"
11 #include "nsString.h"
12 #include "nsTArray.h"
13
14 namespace mozilla {
15 namespace safebrowsing {
16
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() {}
27
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);
34
35 bool Has(uint32_t chunk) const;
36
37 uint32_t Length() const { return mChunks.Length(); }
38
39 nsresult Write(nsIOutputStream* aOut) {
40 return WriteTArray(aOut, mChunks);
41 }
42
43 nsresult Read(nsIInputStream* aIn, uint32_t aNumElements) {
44 return ReadTArray(aIn, &mChunks, aNumElements);
45 }
46
47 uint32_t *Begin() { return mChunks.Elements(); }
48 uint32_t *End() { return mChunks.Elements() + mChunks.Length(); }
49
50 private:
51 nsTArray<uint32_t> mChunks;
52 };
53
54 }
55 }
56
57 #endif

mercurial