spl

Why must I rewind IteratorIterator

淺唱寂寞╮ 提交于 2019-11-29 15:38:46
$arrayIter = new ArrayIterator( array(1, 2) ); $iterIter = new IteratorIterator($arrayIter); var_dump($iterIter->valid()); //false var_dump($arrayIter->valid()); //true If I first call $iterIter->rewind() , then $iterIter->valid() is true. I'm curious why it requires that rewind() be called. I imagine there's good reason for it, but I would have expected it to simply start iteration at whatever state it's inner iterator is in, and leave it as an option to rewind before beginning iteration. calling next() also seems to put it in a "valid" state(although it advances to the next position,

P3391 【模板】文艺平衡树(Splay)

懵懂的女人 提交于 2019-11-28 20:48:01
题面 https://www.luogu.org/problem/P3391 题解 #include<cstdio> #include<iostream> using namespace std; const int start = 100050 ; struct node { int ch[2],fa; int v,siz; bool turn; } a[100500]; int n,m,cnt; bool opt(int x) { return a[a[x].fa].ch[1]==x; } void pushdown(int now) { if (!now || !a[now].turn) return; a[now].turn=false; swap(a[a[now].ch[0]].ch[0],a[a[now].ch[0]].ch[1]); a[a[now].ch[0]].turn^=1; swap(a[a[now].ch[1]].ch[0],a[a[now].ch[1]].ch[1]); a[a[now].ch[1]].turn^=1; } void rotate(int x) { int y=a[x].fa,z=a[y].fa; bool s=opt(x); pushdown(z); pushdown(y); pushdown(x); a[z].ch[opt(y)]=x;

after using $files = new DirectoryIterator() in PHP, how do you sort the items?

好久不见. 提交于 2019-11-28 13:47:45
We can get the files in a directory in PHP by $files = new DirectoryIterator() after that is there an easy way to sort the items in a particular order for displaying them? thanks. gapple It doesn't look like there is a way to sort the data within the iterator. You could place the display data into an intermediary array, with a key of the value you wish to sort by, and call ksort() on the array. This will take two passes over the data however. $path = "."; $files = new DirectoryIterator($path); $files_array = array(); while($files->valid()) { // sort key, ie. modified timestamp $key = $files-

Throwing Exceptions in an SPL autoloader?

☆樱花仙子☆ 提交于 2019-11-28 11:29:51
Is there a way to throw exceptions from an SPL Autoloader in PHP in case it fails? It doesn't seem to work under PHP 5.2.11. class SPLAutoLoader{ public static function autoloadDomain($className) { if(file_exists('test/'.$className.'.class.php')){ require_once('test/'.$className.'.class.php'); return true; } throw new Exception('File not found'); } } //end class //start spl_autoload_register( array('SPLAutoLoader', 'autoloadDomain') ); try{ $domain = new foobarDomain(); }catch(Exception $c){ echo 'File not found'; } When the above code is called, there is no sign of an exception, instead I get

BZOJ 2759 一个动态树好题 (LCT)

旧城冷巷雨未停 提交于 2019-11-28 10:08:02
滚回来学文化课了…… 题目链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2759 题解 LCT,显然的做法是维护链上所有一次函数的复合。 如何处理根的问题? 考虑所有的连通块都建成有根树,另外记录每个根的父亲。 修改父亲的时候,如果修改的是根,那么要么直接改,要么合并两个连通块,根变为非根;如果修改的不是根,要特判分裂了两个连通块导致根的父亲进了新的连通块的情况,如果如此则需重新合并,根变为非根,其余直接改即可。 时间复杂度 \(O(n\log n)\) . 代码 #include<cstdio> #include<cstdlib> #include<iostream> #include<cassert> using namespace std; void read(int &x) { int f=1;x=0;char s=getchar(); while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();} while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();} x*=f; } const int N = 3e4; const int P = 1e4+7; int inv[P+2]; struct Data { int a,b; Data() {}

“Indirect modification of overloaded element of SplFixedArray has no effect”

跟風遠走 提交于 2019-11-28 08:58:14
Why the following $a = new SplFixedArray(5); $a[0] = array(1, 2, 3); $a[0][0] = 12345; // here var_dump($a); produces Notice: Indirect modification of overloaded element of SplFixedArray has no effect in <file> on line <indicated> Is it a bug? How do you deal with multidimensional SplFixedArrays then? Any workarounds? First, the problem is related to all classes which implement ArrayAccess it is not a special problem of SplFixedArray only. When you accessing elements from SplFixedArray using the [] operator it behaves not exactly like an array. Internally it's offsetGet() method is called, and

Difference between DirectoryIterator and FileSystemIterator

社会主义新天地 提交于 2019-11-28 06:42:39
PHP 5 introduced DirectoryIterator , and PHP 5.3 introduced FileSystemIterator . FileSystemIterator extends DirectoryIterator , but the documentation fails to say what extra features it brings. Can you tell the difference between DirectoryIterator and FileSystemIterator ? dbf This goes out of the top of my head, where I sort of got caught in the changes prior to PHP 5.3 that were going to change in 5.3 and later, concerning the SPL (StandardPHPLibrary) and stuff that were going to be moved to the (horrible) PECL extensions. The major thing that changed since 5.3, was that the SPL became an

php get full path of file in a folder

那年仲夏 提交于 2019-11-28 06:17:40
问题 I have a folder which named data . In this data folder, there are files and folders. In this folders there is files and folders.... Continues like this... I need to get all file path's (include sub directories' files). I have a php code: function dirToArray($dir) { $contents = array(); foreach (scandir($dir) as $node) { if ($node == '.' || $node == '.htaccess' || $node == '..' || $node == '.tmb' || $node == '.quarantine') continue; if (is_dir($dir . '/' . $node)) { $contents[$node] =

Peek ahead when iterating an array in PHP

假装没事ソ 提交于 2019-11-28 04:22:41
Is it possible to "peek ahead" while iterating an array in PHP 5.2? For example, I often use foreach to manipulate data from an array: foreach($array as $object) { // do something } But I often need to peek at the next element while going through the array. I know I could use a for loop and reference the next item by it's index ( $array[$i+1] ), but it wouldn't work for associative arrays. Is there any elegant solution for my problem, perhaps involving SPL? You can use the CachingIterator for this purpose. Here is an example: $collection = new CachingIterator( new ArrayIterator( array('Cat',

uboot中Kconfig架构的理解

此生再无相见时 提交于 2019-11-28 00:33:12
1./u-boot-2019.07/Kconfig 是顶层Kconfig mainmenu "U-Boot $UBOOTVERSION Configuration" #这是总menu 2.source "arch/Kconfig" #然后就引用了arch目录下的Kconfig 这个Kconfig中可以选择不同的架构,有arm M68K MIPS等 choice prompt "Architecture select" default SANDBOX config ARC bool "ARC architecture" select ARCH_EARLY_INIT_R select ARC_TIMER select CLK select HAVE_PRIVATE_LIBGCC select SUPPORT_OF_CONTROL select TIMER config ARM bool "ARM architecture" select CREATE_ARCH_SYMLINK select HAVE_PRIVATE_LIBGCC if !ARM64 select SUPPORT_OF_CONTROL config M68K bool "M68000 architecture" select HAVE_PRIVATE_LIBGCC select SYS_BOOT_GET_CMDLINE