Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: net/disk_cache/addr.h

Issue 53313004: Disk cache v3: The main index table. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: remove From*Address use Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/disk_cache/disk_format_base.h » ('j') | net/disk_cache/v3/index_table.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is an internal class that handles the address of a cache record. 5 // This is an internal class that handles the address of a cache record.
6 // See net/disk_cache/disk_cache.h for the public interface of the cache. 6 // See net/disk_cache/disk_cache.h for the public interface of the cache.
7 7
8 #ifndef NET_DISK_CACHE_ADDR_H_ 8 #ifndef NET_DISK_CACHE_ADDR_H_
9 #define NET_DISK_CACHE_ADDR_H_ 9 #define NET_DISK_CACHE_ADDR_H_
10 10
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 // 7 = evicted entries block file 47 // 7 = evicted entries block file
48 // 48 //
49 // If separate file: 49 // If separate file:
50 // 0000 1111 1111 1111 1111 1111 1111 1111 : file# 0 - 268,435,456 (2^28) 50 // 0000 1111 1111 1111 1111 1111 1111 1111 : file# 0 - 268,435,456 (2^28)
51 // 51 //
52 // If block file: 52 // If block file:
53 // 0000 1100 0000 0000 0000 0000 0000 0000 : reserved bits 53 // 0000 1100 0000 0000 0000 0000 0000 0000 : reserved bits
54 // 0000 0011 0000 0000 0000 0000 0000 0000 : number of contiguous blocks 1-4 54 // 0000 0011 0000 0000 0000 0000 0000 0000 : number of contiguous blocks 1-4
55 // 0000 0000 1111 1111 0000 0000 0000 0000 : file selector 0 - 255 55 // 0000 0000 1111 1111 0000 0000 0000 0000 : file selector 0 - 255
56 // 0000 0000 0000 0000 1111 1111 1111 1111 : block# 0 - 65,535 (2^16) 56 // 0000 0000 0000 0000 1111 1111 1111 1111 : block# 0 - 65,535 (2^16)
57 //
58 // Note that an Addr can be used to "point" to a variety of different objects,
59 // from a given type of entry to random blobs of data. Conceptually, an Addr is
60 // just a number that someone can inspect to find out how to locate the desired
61 // record. Most users will not care about the specific bits inside Addr, for
62 // example, what parts of it point to a file number; only the code that has to
63 // select a specific file would care about those specific bits.
64 //
65 // From a general point of view, an Addr has a total capacity of 2^24 entities,
66 // in that it has 24 bits that can identify individual records. Note that the
67 // address space is bigger for independent files (2^28), but that would not be
68 // the general case.
57 class NET_EXPORT_PRIVATE Addr { 69 class NET_EXPORT_PRIVATE Addr {
58 public: 70 public:
59 Addr() : value_(0) {} 71 Addr() : value_(0) {}
60 explicit Addr(CacheAddr address) : value_(address) {} 72 explicit Addr(CacheAddr address) : value_(address) {}
61 Addr(FileType file_type, int max_blocks, int block_file, int index) { 73 Addr(FileType file_type, int max_blocks, int block_file, int index) {
62 value_ = ((file_type << kFileTypeOffset) & kFileTypeMask) | 74 value_ = ((file_type << kFileTypeOffset) & kFileTypeMask) |
63 (((max_blocks - 1) << kNumBlocksOffset) & kNumBlocksMask) | 75 (((max_blocks - 1) << kNumBlocksOffset) & kNumBlocksMask) |
64 ((block_file << kFileSelectorOffset) & kFileSelectorMask) | 76 ((block_file << kFileSelectorOffset) & kFileSelectorMask) |
65 (index & kStartBlockMask) | kInitializedMask; 77 (index & kStartBlockMask) | kInitializedMask;
66 } 78 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 121 }
110 122
111 static Addr FromEntryAddress(uint32 value) { 123 static Addr FromEntryAddress(uint32 value) {
112 return Addr(kInitializedMask + (BLOCK_ENTRIES << kFileTypeOffset) + value); 124 return Addr(kInitializedMask + (BLOCK_ENTRIES << kFileTypeOffset) + value);
113 } 125 }
114 126
115 static Addr FromEvictedAddress(uint32 value) { 127 static Addr FromEvictedAddress(uint32 value) {
116 return Addr(kInitializedMask + (BLOCK_EVICTED << kFileTypeOffset) + value); 128 return Addr(kInitializedMask + (BLOCK_EVICTED << kFileTypeOffset) + value);
117 } 129 }
118 130
131 // Returns the part of the address that could be stored by the index.
132 uint32 ToIndexEntryAddress() const {
133 return value_ & (kFileSelectorMask | kStartBlockMask);
134 }
135
119 static int BlockSizeForFileType(FileType file_type) { 136 static int BlockSizeForFileType(FileType file_type) {
120 switch (file_type) { 137 switch (file_type) {
121 case RANKINGS: 138 case RANKINGS:
122 return 36; 139 return 36;
123 case BLOCK_256: 140 case BLOCK_256:
124 return 256; 141 return 256;
125 case BLOCK_1K: 142 case BLOCK_1K:
126 return 1024; 143 return 1024;
127 case BLOCK_4K: 144 case BLOCK_4K:
128 return 4096; 145 return 4096;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 static const uint32 kFileSelectorOffset = 16; 192 static const uint32 kFileSelectorOffset = 16;
176 static const uint32 kStartBlockMask = 0x0000FFFF; 193 static const uint32 kStartBlockMask = 0x0000FFFF;
177 static const uint32 kFileNameMask = 0x0FFFFFFF; 194 static const uint32 kFileNameMask = 0x0FFFFFFF;
178 195
179 CacheAddr value_; 196 CacheAddr value_;
180 }; 197 };
181 198
182 } // namespace disk_cache 199 } // namespace disk_cache
183 200
184 #endif // NET_DISK_CACHE_ADDR_H_ 201 #endif // NET_DISK_CACHE_ADDR_H_
OLDNEW
« no previous file with comments | « no previous file | net/disk_cache/disk_format_base.h » ('j') | net/disk_cache/v3/index_table.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698