热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

没有副本的数组堆栈算法-Anarraystackalgorithmwithoutcopy

Ihaveaflashlite3applicationwithnavigationconsistingoficonstheusercanbrowseleftorrigh

I have a flashlite3 application with navigation consisting of icons the user can browse left or right through infinitely.

我有一个flashlite3应用程序,导航组成的图标,用户可以无限地向左或向右浏览。

The basic algorithm i'm using now works (and is adequate for this project) however, part of the solution depends on a duplicate of the array of icons. Depending on the number of items in the array, and/or the size of the element contents, this solution could become less efficient. I'm interested in a solution or algorithm(in any language) that could achieve the same thing while being scalable & efficient.

我现在使用的基本算法有效(并且适用于此项目)但是,解决方案的一部分取决于图标数组的副本。根据数组中项目的数量和/或元素内容的大小,此解决方案可能效率降低。我对可扩展和高效的解决方案或算法(任何语言)感兴趣,可以实现相同的目标。

Heres a portion of relevant code in the setter function for mutating the '_selectedItem' property, which:

下面是setter函数中相关代码的一部分,用于改变'_selectedItem'属性,其中:

  1. Evaluates the current '_selectedItem' and the new '_value'
  2. 评估当前的'_selectedItem'和新的'_value'

  3. Based on step 1 pop,unshifts right, or shift,pops left
  4. 基于第1步弹出,向右移位或向左移动,向左弹出

  5. Repeats step 2 until the icon matching the '_selectedItem' is in the center of the array
  6. 重复步骤2,直到匹配'_selectedItem'的图标位于数组的中心

This code runs using 3 arrays:

此代码使用3个数组运行:

  1. [static] Array of positions. There are 5 icons, 3 are visible at a time, so position 0 is off stage, position 1 is 1/3, position 2 is 1/2 ..
  2. [静态]阵列数组。有5个图标,一次可见3个,因此位置0离开阶段,位置1为1/3,位置2为1/2。

  3. When instantiating the icons 2 arrays are created: _viewArray & _icons. The order of _viewArray mimics the order to be displayed and _icons is left alone and used for the loop condition checking
  4. 实例化图标时,会创建2个数组:_viewArray&_icons。 _viewArray的顺序模仿要显示的顺序,_icons保持不变并用于循环条件检查

///Actionscript2///

    public function set selectedItem(value:Number)
    {
        var w=Stage.width;

        if(value > _icons.length-1)
        {
            value=0;
        }else if(value <0)
        {
            value=_icons.length-1;
        }

        if(value > _selectedIndex)
        {
            while(_viewArray[Math.floor(_icons.length*.5)] != _icons[value])
            {
                var element;
                element=_viewArray.pop();
                _viewArray.unshift(element);
            }
        }else if(value <_selectedIndex)
        {
            while(_viewArray[Math.floor(_icons.length*.5)]!=_icons[value])
            {
                var element;
                element=_viewArray.shift();
                _viewArray.push(element);
            }           
        }




        for(var i:Number=0;i<_viewArray.length;i++)
        {
            if(i>=1 && i<= _icons.length-2)
            {
                _viewArray[i]._visible=true;
            }else
            {
                _viewArray[i]._visible=false;
            }
            Tweener.addTween(_viewArray[i],{_x:positions[i],_alpha:80,time:.5,transition:'elasticIn'})
        }


        Tweener.addTween(_icons[(_viewArray.length*.5)-1],{_alpha:100,time:.0,transition:'elasticIn'});
        Tweener.addTween(_selectedServiceIndicator,{_alpha:0,time:.3,transition:'elasticIn',onComplete:function() {Tweener.addTween(this,{_alpha:100,time:.2,transition:'elasticIn'});}});

        var eventObject:Object = {target:this, type:'SelectedItemChange'};
        eventObject.value=value;

        for(var key in _serviceData[value])
        eventObject[key]=_serviceData[value][key];

        dispatchEvent(eventObject);
        _selectedIndex=value;
    }

1 个解决方案

#1


Why does each element of the _viewArray has to actually store the icon, rather than only the index into the _icons array? This way you only have the icons stored once, and _viewArray just stores their presentation order.

为什么_viewArray的每个元素都必须实际存储图标,而不是仅将索引存储到_icons数组中?这样您只能存储一次图标,_viewArray只存储它们的演示顺序。


推荐阅读
  • 本文介绍了Perl的测试框架Test::Base,它是一个数据驱动的测试框架,可以自动进行单元测试,省去手工编写测试程序的麻烦。与Test::More完全兼容,使用方法简单。以plural函数为例,展示了Test::Base的使用方法。 ... [详细]
  • 我正在使用数组列表通过构建一个交互式菜单供用户选择来存储来自用户输入的值。到目前为止,我的两个选择是为用户提供向列表输入数据和读取列表的全部内容。到目前为止,我创建的代码由两个类组成。 ... [详细]
  • python PyQt Tablewidget的基本操作
    PYQT控件之Tabl ... [详细]
  • 在这一期的SendMessage函数应用中,我将向大家介绍如何利用消息函数来扩展树型列表(TreeView)控件的功能相信对于树型列表控件大家十分的熟悉, ... [详细]
  • 互联网世界 9 种基本的商业模式
    互联网世界9种基本的商业模式一个商业模式是运行一个公司的方法;通过该模式的运作,一个公司能维持自己的生存,就是说,能有收益。商业模式意味着一个公司是如何通过在价值链中定位自己,从而获 ... [详细]
  • Adapter相当于C(Controller,控制器),listView相当于V(View,视图)用于显示数据为ListView提供数据的List,数组或数据库相当于MVC模式中的 ... [详细]
  • IIS6.0提供一个重新设计的万维网发布服务(WorldWideWebPublishingService)架构,可以帮助你为你的网站构建更好的性能、可靠、可扩展性(scalabil ... [详细]
  • 导读:今天编程笔记来给各位分享关于php变量命名规范是什么的相关内容,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!本文目录一览: ... [详细]
  • 1、获取类身上的成员变量--class_copyIvarListif([badgeViewChildisKindOfClass:NSClassFromString(_UIBadg ... [详细]
  • java中打开文件显示_在默认文件资源管理器中打开文件,并使用JavaFX或普通Java突出显示它...
    我想做标题所说的.部分解决方案例如,在Windows中,您可以使用以下代码在默认资源管理器中打开文件并突出显示它.(虽然它需要修改包含空格的文件):***Openst ... [详细]
  • 外层|条件下_MySQL还能这样玩第五篇之视图应该这样玩
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了MySQL还能这样玩---第五篇之视图应该这样玩相关的知识,希望对你有一定的参考价值。 ... [详细]
  • 作业迁移
    背景:数据库服务器更换,1、数据库迁移(BACKUPRESTORE);2、数据库登录名用户迁移(注意孤立用户);3、作业迁移数据库迁移,备份数据库、拷贝备份文件到新服务器,还原数据 ... [详细]
  • 技术点:1、通过已知的网页路径获得流2、把流转换成字节数组3、把字节数组转换成String字符串显示在TextView控件中一、获得流publicstaticSt ... [详细]
  • 配置OracleACFS集群文件系统
    配置OracleACFS集群文件系统               2012-07-1010:18:39标签:asmacfs版权声明:原创作品,谢绝转载!否则将追究法律责任。     ... [详细]
  •     算算自己工作已经快一年了,不管中间有过什么挫折,但现在感觉自己有了很大的成长。想想曾经还畏惧过技术,觉得居然入了一个需要不断学习的行业,而自己连怎么学都还没搞清楚。但通过这 ... [详细]
author-avatar
今日屎汰濃
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有