官术网_书友最值得收藏!

A better transaction log

So, the list of requirements got expanded:

  • Move forward through the log
  • Move backward through the log
  • Moves don't consume the log

A nice fit for the doubly linked list, so the existing transaction log can be upgraded! With the pointers to both neighbors of a node, it can solve the problem. However, what about moving through the list without removing elements?

For that, another concept is required: iterators. Rust's iterators are leaning on the functional side of programming and provide a versatile interface for integrating with all kinds of other data structures and commands across the language. For example, for loops will pick up on the iterator and behave as expected.

Iterators are pointers to the current item with a method called next() that produces the next item while moving the pointer forward! This concept is applied a lot when using a more functional approach to working with collections: by chaining them together and applying a function after invoking next(), going through a list can be very efficient. Check the Further reading section and the last chapter of this book for more information!

The data model is going to look like the singly linked list, so most of the operations can be used as they are—they only need to be upgraded to work with the back-pointer as well.

主站蜘蛛池模板: 霍州市| 稷山县| 石渠县| 沂源县| 甘南县| 景洪市| 丰原市| 平邑县| 连云港市| 江油市| 柘荣县| 镇安县| 安达市| 衡南县| 西安市| 东辽县| 怀化市| 子洲县| 兰坪| 庆元县| 旺苍县| 嘉黎县| 汉中市| 西青区| 浑源县| 黄浦区| 东乡县| 辉县市| 株洲县| 南江县| 庆云县| 松阳县| 常山县| 松阳县| 肃北| 乡城县| 霞浦县| 平定县| 宁南县| 辽中县| 杂多县|