containers

c# stack queue combination

雨燕双飞 提交于 2019-11-30 06:35:12
is there in C# some already defined generic container which can be used as Stack and as Queue at the same time? I just want to be able to append elements either to the end, or to the front of the queue thanks Check the LinkedList class. LinkedList<int> list = new LinkedList<int>(); list.AddFirst(1); list.AddLast(2); list.AddFirst(0); Here's my implementation of an immutable deque : http://blogs.msdn.com/ericlippert/archive/2008/02/12/immutability-in-c-part-eleven-a-working-double-ended-queue.aspx Notice that this is an immutable double-ended-queue. Normally you probably think of a queue as

Why does Docker need a Union File System

余生颓废 提交于 2019-11-30 06:26:11
问题 What exactly does Docker do with Union File system (like AUFS) to create the containers ? If Docker had to use a regular file system instead of a union file system what will be the disadvantages ? I am looking for specific technical details/internals and not a high level answer. 回答1: It is used to: avoid duplicating a complete set of files each time you run an image as a new container isolate changes to a container filesystem in its own layer, allowing for that same container to be restarted

How to get a sub array of array in Java, without copying data?

╄→гoц情女王★ 提交于 2019-11-30 05:35:26
I have some library of classes, working with my data, which is being read into buffer. Is it possible somehow to avoid copying arrays again and again, passing parts of data deeper and deeper into processing methods? Well, it sounds strange, but in my particular case, there's a special writer, which divides data into blocks and writes them individually into different locations, so it just performs System.arraycopy, gets what it needs and calls underlying writer, with that new sub array. And this happens many times. What is the best approach to refactor such code? Many classes in Java accept a

Wrapping dynamic array into STL/Boost container?

核能气质少年 提交于 2019-11-30 05:30:11
I need to wrap a dynamically allocated array(from a = new double[100] for example) into std::vector(preferably) without copying the array. This restriction is imposed by that the array I want to wrap is mmaped from a file, so just doing vector(a, a+size) will double the memory usage. Is any tricks to do that? One of the best solutions for this is something like STLSoft's array_proxy<> template. Unfortunately, the doc page generated from the source code by doxygen isn't a whole lot of help understanding the template. The source code might actually be a bit better: http://www.stlsoft.org/doc-1.9

How to expose audio from Docker container to a Mac?

心不动则不痛 提交于 2019-11-30 04:58:27
I know it's possible by using pulse audio on a Linux host system But paprefs is built for linux not mac. The Docker-for-Mac VM doesn't have any sound passthrough device, so there isn't anything that you could take advantage of from that angle. By contrast, a virtualbox or vmware fusion VM does have the ability to do passthrough audio. I was able to get pulseaudio installed and working on OSX with the following command: brew install pulseaudio I was able to verify this worked by running the following, hearing sound come out of my speakers: paplay cockatiel.wav My next step is to find an image

STL container function return values

六月ゝ 毕业季﹏ 提交于 2019-11-30 03:55:32
问题 When looking over the member functions of the STL containers, an odd thought occurred to me. Why don't functions like std::vector<T>::push_back(T) not have an (optional) return value (iterator or even a reference to the appended object)? I know std::string functions like insert and erase return iterators, but that's for obvious reasons. I'd think it'd often save a second line of code that often follows these function calls. I'm sure the designers of C++ have a very good reason, please

Mapping between stl C++ and C# containers

随声附和 提交于 2019-11-30 03:38:31
Can someone point out a good mapping between the usual C++ STL containers such as vector, list, map, set, multimap... and the C# generic containers? I'm used to the former ones and somehow I've accustomed myself to express algorithms in terms of those containers. I'm having some hard time finding the C# equivalent to those. Thank you! Scott Wisniewski Here's a rough equivalence: Dictionary<K,V> <=> unordered_map<K,V> HashSet<T> <=> unordered_set<T> List<T> <=> vector<T> LinkedList<T> <=> list<T> The .NET BCL (base class library) does not have red-black trees (stl map) or priority queues (make

Partial match for the key of a std::map

寵の児 提交于 2019-11-30 03:04:30
I have an std::map and I want to search for a key using a substring. For example, I have the following code: #include <iostream> #include <map> #include <string> using namespace std; typedef std::map<std::string, std::string> TStrStrMap; typedef std::pair<std::string, std::string> TStrStrPair; int main(int argc, char *argv[]) { TStrStrMap tMap; tMap.insert(TStrStrPair("John", "AA")); tMap.insert(TStrStrPair("Mary", "BBB")); tMap.insert(TStrStrPair("Mother", "A")); tMap.insert(TStrStrPair("Marlon", "C")); return 0; } Now, I want to search for the position that holds the substring "Marl" and not

Start service using systemctl inside docker conatiner

牧云@^-^@ 提交于 2019-11-30 02:54:47
问题 In my Dockerfile I am trying to install multiple services and want to have them all start up automatically when I launch the container. One among the services is mysql and when I launch the container I don't see the mysql service starting up. When I try to start manually, I get the error: Failed to get D-Bus connection: Operation not permitted Dockerfile: FROM centos:7 RUN yum -y install mariadb mariadb-server COPY start.sh start.sh CMD ["/bin/bash", "start.sh"] My start.sh file: service

How to make a C++ map container where the key is part of the value?

泪湿孤枕 提交于 2019-11-30 01:27:08
问题 I want to store a bunch of key-value objects, but where the value object itself (and references to it) knows its key. I also want to efficiently lookup these objects given only the key. class SomeObject { private: //String or integer. int seem cheap enough to duplicate with std::map, but //strings seem pretty expensive when there may be thousands of objects in existence. //Reference/Pointer to key is fine const SomeOtherObject key; ...other stuff... public: ...methods, some of which use the