| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 static const int kRangeCanonicalizeMax = 0x346; | 207 static const int kRangeCanonicalizeMax = 0x346; |
| 208 static const int kStartMarker = (1 << 24); | 208 static const int kStartMarker = (1 << 24); |
| 209 static const int kPayloadMask = (1 << 24) - 1; | 209 static const int kPayloadMask = (1 << 24) - 1; |
| 210 | 210 |
| 211 private: | 211 private: |
| 212 uc16 from_; | 212 uc16 from_; |
| 213 uc16 to_; | 213 uc16 to_; |
| 214 }; | 214 }; |
| 215 | 215 |
| 216 | 216 |
| 217 template <typename Node, class Callback> | |
| 218 static void DoForEach(Node* node, Callback* callback); | |
| 219 | |
| 220 | |
| 221 // A zone splay tree. The config type parameter encapsulates the | |
| 222 // different configurations of a concrete splay tree: | |
| 223 // | |
| 224 // typedef Key: the key type | |
| 225 // typedef Value: the value type | |
| 226 // static const kNoKey: the dummy key used when no key is set | |
| 227 // static const kNoValue: the dummy value used to initialize nodes | |
| 228 // int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function | |
| 229 // | |
| 230 template <typename Config> | |
| 231 class ZoneSplayTree : public ZoneObject { | |
| 232 public: | |
| 233 typedef typename Config::Key Key; | |
| 234 typedef typename Config::Value Value; | |
| 235 | |
| 236 class Locator; | |
| 237 | |
| 238 ZoneSplayTree() : root_(NULL) { } | |
| 239 | |
| 240 // Inserts the given key in this tree with the given value. Returns | |
| 241 // true if a node was inserted, otherwise false. If found the locator | |
| 242 // is enabled and provides access to the mapping for the key. | |
| 243 bool Insert(const Key& key, Locator* locator); | |
| 244 | |
| 245 // Looks up the key in this tree and returns true if it was found, | |
| 246 // otherwise false. If the node is found the locator is enabled and | |
| 247 // provides access to the mapping for the key. | |
| 248 bool Find(const Key& key, Locator* locator); | |
| 249 | |
| 250 // Finds the mapping with the greatest key less than or equal to the | |
| 251 // given key. | |
| 252 bool FindGreatestLessThan(const Key& key, Locator* locator); | |
| 253 | |
| 254 // Find the mapping with the greatest key in this tree. | |
| 255 bool FindGreatest(Locator* locator); | |
| 256 | |
| 257 // Finds the mapping with the least key greater than or equal to the | |
| 258 // given key. | |
| 259 bool FindLeastGreaterThan(const Key& key, Locator* locator); | |
| 260 | |
| 261 // Find the mapping with the least key in this tree. | |
| 262 bool FindLeast(Locator* locator); | |
| 263 | |
| 264 // Remove the node with the given key from the tree. | |
| 265 bool Remove(const Key& key); | |
| 266 | |
| 267 bool is_empty() { return root_ == NULL; } | |
| 268 | |
| 269 // Perform the splay operation for the given key. Moves the node with | |
| 270 // the given key to the top of the tree. If no node has the given | |
| 271 // key, the last node on the search path is moved to the top of the | |
| 272 // tree. | |
| 273 void Splay(const Key& key); | |
| 274 | |
| 275 class Node : public ZoneObject { | |
| 276 public: | |
| 277 Node(const Key& key, const Value& value) | |
| 278 : key_(key), | |
| 279 value_(value), | |
| 280 left_(NULL), | |
| 281 right_(NULL) { } | |
| 282 Key key() { return key_; } | |
| 283 Value value() { return value_; } | |
| 284 Node* left() { return left_; } | |
| 285 Node* right() { return right_; } | |
| 286 private: | |
| 287 friend class ZoneSplayTree; | |
| 288 friend class Locator; | |
| 289 Key key_; | |
| 290 Value value_; | |
| 291 Node* left_; | |
| 292 Node* right_; | |
| 293 }; | |
| 294 | |
| 295 // A locator provides access to a node in the tree without actually | |
| 296 // exposing the node. | |
| 297 class Locator { | |
| 298 public: | |
| 299 explicit Locator(Node* node) : node_(node) { } | |
| 300 Locator() : node_(NULL) { } | |
| 301 const Key& key() { return node_->key_; } | |
| 302 Value& value() { return node_->value_; } | |
| 303 void set_value(const Value& value) { node_->value_ = value; } | |
| 304 inline void bind(Node* node) { node_ = node; } | |
| 305 private: | |
| 306 Node* node_; | |
| 307 }; | |
| 308 | |
| 309 template <class Callback> | |
| 310 void ForEach(Callback* c) { | |
| 311 DoForEach<typename ZoneSplayTree<Config>::Node, Callback>(root_, c); | |
| 312 } | |
| 313 | |
| 314 private: | |
| 315 Node* root_; | |
| 316 }; | |
| 317 | |
| 318 | |
| 319 // A set of unsigned integers that behaves especially well on small | 217 // A set of unsigned integers that behaves especially well on small |
| 320 // integers (< 32). May do zone-allocation. | 218 // integers (< 32). May do zone-allocation. |
| 321 class OutSet: public ZoneObject { | 219 class OutSet: public ZoneObject { |
| 322 public: | 220 public: |
| 323 OutSet() : first_(0), remaining_(NULL), successors_(NULL) { } | 221 OutSet() : first_(0), remaining_(NULL), successors_(NULL) { } |
| 324 OutSet* Extend(unsigned value); | 222 OutSet* Extend(unsigned value); |
| 325 bool Get(unsigned value); | 223 bool Get(unsigned value); |
| 326 static const unsigned kFirstLimit = 32; | 224 static const unsigned kFirstLimit = 32; |
| 327 | 225 |
| 328 private: | 226 private: |
| (...skipping 1047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1376 Handle<String> pattern, | 1274 Handle<String> pattern, |
| 1377 bool is_ascii); | 1275 bool is_ascii); |
| 1378 | 1276 |
| 1379 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); | 1277 static void DotPrint(const char* label, RegExpNode* node, bool ignore_case); |
| 1380 }; | 1278 }; |
| 1381 | 1279 |
| 1382 | 1280 |
| 1383 } } // namespace v8::internal | 1281 } } // namespace v8::internal |
| 1384 | 1282 |
| 1385 #endif // V8_JSREGEXP_H_ | 1283 #endif // V8_JSREGEXP_H_ |
| OLD | NEW |