mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-11-04 05:19:11 +00:00 
			
		
		
		
	hashlib: add insertion order const iterator
This commit is contained in:
		
							parent
							
								
									430adb3b59
								
							
						
					
					
						commit
						d6d1f16c43
					
				
					 2 changed files with 25 additions and 4 deletions
				
			
		| 
						 | 
				
			
			@ -569,13 +569,16 @@ public:
 | 
			
		|||
		int index;
 | 
			
		||||
		const_iterator(const dict *ptr, int index) : ptr(ptr), index(index) { }
 | 
			
		||||
	public:
 | 
			
		||||
		typedef std::forward_iterator_tag iterator_category;
 | 
			
		||||
		typedef std::bidirectional_iterator_tag iterator_category;
 | 
			
		||||
		typedef std::pair<K, T> value_type;
 | 
			
		||||
		typedef ptrdiff_t difference_type;
 | 
			
		||||
		typedef std::pair<K, T>* pointer;
 | 
			
		||||
		typedef std::pair<K, T>& reference;
 | 
			
		||||
		typedef const std::pair<K, T>* pointer;
 | 
			
		||||
		typedef const std::pair<K, T>& reference;
 | 
			
		||||
		const_iterator() { }
 | 
			
		||||
		const_iterator operator++() { index--; return *this; }
 | 
			
		||||
		const_iterator operator++(int) { const_iterator tmp = *this; index--; return tmp; }
 | 
			
		||||
		const_iterator operator--() { index++; return *this; }
 | 
			
		||||
		const_iterator operator--(int) { const_iterator tmp = *this; index++; return tmp; }
 | 
			
		||||
		const_iterator operator+=(int amt) { index -= amt; return *this; }
 | 
			
		||||
		bool operator<(const const_iterator &other) const { return index > other.index; }
 | 
			
		||||
		bool operator==(const const_iterator &other) const { return index == other.index; }
 | 
			
		||||
| 
						 | 
				
			
			@ -609,6 +612,13 @@ public:
 | 
			
		|||
		const std::pair<K, T> *operator->() const { return &ptr->entries[index].udata; }
 | 
			
		||||
		operator const_iterator() const { return const_iterator(ptr, index); }
 | 
			
		||||
	};
 | 
			
		||||
	using reverse_iterator = std::reverse_iterator<const_iterator>;
 | 
			
		||||
	reverse_iterator rbegin() const {
 | 
			
		||||
		return std::make_reverse_iterator(end());
 | 
			
		||||
	}
 | 
			
		||||
	reverse_iterator rend() const {
 | 
			
		||||
		return std::make_reverse_iterator(begin());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	constexpr dict()
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -858,7 +868,7 @@ public:
 | 
			
		|||
 | 
			
		||||
	const_iterator begin() const { return const_iterator(this, int(entries.size())-1); }
 | 
			
		||||
	const_iterator element(int n) const { return const_iterator(this, int(entries.size())-1-n); }
 | 
			
		||||
	const_iterator end() const { return const_iterator(nullptr, -1); }
 | 
			
		||||
	const_iterator end() const { return const_iterator(this, -1); }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
template<typename K, typename OPS>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,7 @@
 | 
			
		|||
// do not depend on any other components of yosys (except stuff like log_*).
 | 
			
		||||
 | 
			
		||||
#include "kernel/yosys.h"
 | 
			
		||||
#include <iterator>
 | 
			
		||||
 | 
			
		||||
#ifndef UTILS_H
 | 
			
		||||
#define UTILS_H
 | 
			
		||||
| 
						 | 
				
			
			@ -276,6 +277,16 @@ inline int ceil_log2(int x)
 | 
			
		|||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
template <typename T>
 | 
			
		||||
auto reversed(const T& container) {
 | 
			
		||||
    struct reverse_view {
 | 
			
		||||
        const T& cont;
 | 
			
		||||
        auto begin() const { return cont.rbegin(); }
 | 
			
		||||
        auto end() const { return cont.rend(); }
 | 
			
		||||
    };
 | 
			
		||||
    return reverse_view{container};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
YOSYS_NAMESPACE_END
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue